Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please explain output of mention source code

 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public abstract class MyClass {

public void test() {
System.out.println("Howdy");

}

public static void main(String[] args) {
MyClass m = new MyClass() {
};

m.test();
}

}

Output: Howdy

Please explain it. Thanks


 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are creating an anonymous class which is a subclass of that abstract class.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java Language Specification link about anonymous classes.
 
Tyson Lindner
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So many tricky java problems. I didn't catch the brackets after "new MyClass()" at first.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic