• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

anonumous class

 
sunilkumar ssuparasmul
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Base {
private void aMethod() {
System.out.println("I am in base ");
}
public Base() {}
public static void main(String args[]){
//case 1
Base b = new Base(){
void aMethod(){
System.out.println("inside main of base b");
}
};
b.aMethod();

// case 2
new Base(){
void aMethod(){
System.out.println("inside anonumous of base ");
}
}.aMethod();
}
}
In the above code since i ahve declared aMethod in base as private , the base object b when calls aMethod it prints that I am in base where as when i tried to do the same in the next case i.e case 2 , i am getting "inside anonumous of base " .
CAN SOMEBODY PLZ HELP ME
------------------
"Winners don't do different things
They do things differently"
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am moving this to Certification Study since it is not related to a specfic Mock Exam error.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic