Constructor | Method |
|
|
Note: An object can also perform any operation like any other method.
Example
public class Main { Main(){ System.out.println("Constructor Called"); } public void show(){ System.out.println("Method Called"); } public static final void main(String[] args) { Main obj1 = new Main(); obj1.show(); } } |
Output
Constructor Called Method Called |
Java interview questions on constructor
- Default constructor
- Does constructor return any value in java?
- Is constructor inherited in java?
- Can you make a constructor final in java?
- Difference between constructor and method in java?
- How to copy values from one object to another java?
- How to overload constructor in java?
- can you create an object without using new operator in java?
- Constructor chaining in java
- Parameterized constructor in java
- Can we call subclass constructor from superclass constructor?
- What happens if you keep return type for a constructor?
- What is the use of private constructor in java?
- Can a constructor call another constructor java?