What is the use of a local class in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the use of a local class in java

is it really useful at all?

28th May 2018, 4:40 PM
ifl
ifl - avatar
8 Answers
+ 3
ifl hi, A local inner class will have access to all the members of the enclosing class and it’ll have access to the local final variables in the scope it’s defined. I think use of local class somehow on specific situation is required where we have to hide our data from outside of class like I have some examples from which I will try to explain you 1) first I take an example encoder decoder project => in this project I have to hide the encryption at encoder side and decryption at decoder side if I create two local classes which store and secure that data for me 2) in microprocessor all codes have some op codes so if I have to make microprocessor then I just create an local class and do everything op codes store in that class which is not accessible outside the class 3)https://coderanch.com/mobile/t/528900/java/Practical-real-world-situations-classes https://www.dineshonjava.com/local-inner-classes-example-in-java/ I hope this link can help you I'm not good in explaining
28th May 2018, 6:06 PM
MsJ
MsJ - avatar
+ 10
Mohit the coder (M.S.D) Haha, I feel honored. Let me just refer to the official tutorial, because it covers the topic perfectly. The official tutorial is sometimes a little confusing and often long to read, but this chapter is really good. Just ask if you have any further questions on the matter. https://docs.oracle.com/javase/tutorial/java/javaOO/whentouse.html
28th May 2018, 6:48 PM
Tashi N
Tashi N - avatar
28th May 2018, 5:48 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 5
GAWEN STEASY yes, thanks for the post. I saw it (or similar ) in quora, but I never felt I the need to use this myself, so checking what people think, or how it is used in real examples... :-)
28th May 2018, 5:51 PM
ifl
ifl - avatar
+ 5
well thanks but yeah if someone good in Java like Tashi N if she do share some knowledge on this then It would be good just in case she is free tagging you for the thread
28th May 2018, 6:14 PM
MsJ
MsJ - avatar
+ 4
Mohit the coder (M.S.D) Interesting examples, thanks.
28th May 2018, 6:10 PM
ifl
ifl - avatar
+ 3
Thanks Tashi N !
29th May 2018, 4:20 PM
ifl
ifl - avatar
+ 2
For example: I used it in a blockchain application, in the blockchain class I made a seperate inner class mining. This makes the code more clean and readable. Can be very usefull for testing/benchmarking as well.
28th May 2018, 4:43 PM
***
*** - avatar