SCJP 6. Learning more now.
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Rahul Sudip Bose wrote:Why do we need inner classes ? Can anyone give me a practical/real world situation where they could be useful ?
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
SCJP 6. Learning more now.
http://plainoldjavaobject.blogspot.in
Lalit Mehra wrote:there can be a lot of examples ... for suppose
you have two classes
1. Animal
2. Dog
Now let's say Dog is your core class that you have to work with ... but just for some requirements you need some generic functionality and you do not want to put that in the Dog class ...
here you go ... you can make another class Animal (inner class) and write your generic code in it ...
and access it from within the Dog class itself ...
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Mohamed Sanaulla wrote:
Not an example for inner class. Its - Super class- Sub class relationship.
http://plainoldjavaobject.blogspot.in
Lalit Mehra wrote:but just for some requirements you need some generic functionality and you do not want to put that in the Dog class
Lalit Mehra wrote: brother i have explicitly written (inner class) please check ...
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
http://plainoldjavaobject.blogspot.in
Lalit Mehra wrote:there can be a lot of examples ... for suppose
you have two classes
1. Animal
2. Dog
Now let's say Dog is your core class that you have to work with ... but just for some requirements you need some generic functionality and you do not want to put that in the Dog class ...
here you go ... you can make another class Animal (inner class) and write your generic code in it ...
and access it from within the Dog class itself ...
SCJP 6. Learning more now.
http://plainoldjavaobject.blogspot.in
Lalit Mehra wrote:
anyways ... just for the sake of providing real world examples ... go through the java API documentation for Collections and Generics ... JAVA API
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Mohamed Sanaulla wrote:
How would Java API provide example for Inner classes? If at all you would ask to refer to the source code- that might have been useful
http://plainoldjavaobject.blogspot.in
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |