Write a Java program to demonstrate a no-argument constructor
The class has a constructor, MyClass(), which has no arguments. Inside this constructor, it prints out "No-argument constructor called" when an object of MyClass is created.
The main method is the entry point of the program. Inside main, it creates an object obj of type MyClass using the constructor MyClass(). When this object is created, the constructor is automatically called, and "No-argument constructor called" is printed.
class MyClass { MyClass() { System.out.println("No-argument constructor called"); } public static void main(String[] args) { MyClass obj = new MyClass(); } }
No-argument constructor called
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions