File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
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: 1270

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: 38363
    
  23
You are creating an anonymous class which is a subclass of that abstract class.
Campbell Ritchie
Sheriff

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

Joined: May 16, 2012
Posts: 172
So many tricky java problems. I didn't catch the brackets after "new MyClass()" at first.
 
wood burning stoves
 
subject: Please explain output of mention source code