New course! Every coder should learn Generative AI!
Try a free lesson+ 1
Yes.
Class Iocal variable also same scope to inner class.. So it possible but inner class local variables are not accessible in outer class if those are private...
If the variables not static, then from static methods, you can't access directly..
+ 1
yes
public class Program {
int a=100;
class B {
int b = 200;
int geta() { return a; }
}
public static void main(String[] args) {
new Program().main2();} void main2(){
B ob = new B();
System.out.println(ob.geta() ); // a 100
System.out.println(ob.b); // b 200
C oc = new C();
System.out.println( oc.getab()); // a+b 300
}
}
class C {
int getab() {
Program.B pb = new Program().new B();
return pb.geta() + pb.b;
}
}