I'm extremely new to Java and have been trying to use Nested class for the first time. I have an outer class with 2 inner class and i'm trying to be able to have the innerclass
class OuterClass {
...
class Person {
class Like {
}
**public static Map<Integer, Like> Likes;**
}
}
Is it possible in Java ? In Golang that would look like this for example :
type Like struct {
}
type Person struct {
Name string
**Likes map[int]Like**
}
I might be going the wrong way and maybe a better OOP approch of doing that exist or is it possible this way ?
Yes this is possible and your code will be like
class Client{
class Outer{
class Phone{
class Like{
public void sayHello(){
System.out.println("Hello");
}
}
public static void method(Outer.Phone.Like g){
l.sayHello();
}
}
}
public static void main(String[] args){
Client q = new Client();
Client.Outer o = q.new Outer();
Client.Outer.Phone p = o.new Phone();
Client.Outer.Phone.Like l = p.new Like();
p.method(l); //call sayHello and print Hello
}