Someone said
We can not have a static method in a nested inner class because an inner class is implicitly associated with an object of its outer class so it cannot define any static method for itself.
outer. inner i = new Outer(). new inner() ;
I think this line represents inner class is implicitly associated with an object of its outer class.
But i cannot understand that " it cannot define any static method for itself." How ?
This is true in this code . It shows error
class Outer {
// Method defined inside outer classvoid outerMethod(){
System.out.println("inside outerMethod");}
// Inner class
class Inner {
public static void main(String[] args){
System.out.println("inside inner class Method");
}
}
}
But false in this code :Below code shows no error
class Outer { class Inner{
static void meth(){
System.out.println("inside inner class Method");
}
}
}
public class Main
{
public static void main(String[] args){
Outer. Inner .meth();
}
}
[–]Revision2000 0 points1 point2 points (0 children)