Q:

Java program to create an anonymous object

0

Java program to create an anonymous object

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this program, we will create an anonymous object. An object which has no reference variable is called an anonymous object.

Program/Source Code:

The source code to create an anonymous object is given below. The given program is compiled and executed successfully.

// Java program to create an anonymous 
// object.

class Sample {
  Sample() {
    System.out.println("Constructor called");
  }

}
public class Main {
  public static void main(String[] args) {
    new Sample();
  }
}

Output:

Constructor called

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now