aspose file tools*
The moose likes Java in General and the fly likes Please explain output of mention source code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Please explain output of mention source code" Watch "Please explain output of mention source code" New topic
Author

Please explain output of mention source code

Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1268

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



No Kaustubh No Fun, Know Kaustubh Know Fun..
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
You are creating an anonymous class which is a subclass of that abstract class.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
Java Language Specification link about anonymous classes.
Tyson Lindner
Ranch Hand

Joined: May 16, 2012
Posts: 135
So many tricky java problems. I didn't catch the brackets after "new MyClass()" at first.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please explain output of mention source code
 
Similar Threads
Variable Initialization
Strange recursive method call! ???
This is from Tip Smarts Sample Paper
equals and this
equals again