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();
}
}
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.
Output: