public class Anony{
private int x = 6;
public static void main(String[] args){
int x =4;
new Anony().new Cell().doSth();
}
class Cell{
coid doSth(){
System.out.println("print key "+x);
}
}
}
The result is "print key 6".
line 5 "new Anony()" and "new Cell()" is the syntax to create anonymous object of Anony class and Cell class.
More example:
https://www.tutorialspoint.com/Anonymous-object-in-Java
No comments :
Post a Comment