Which of the following is/are true about constructors in Java?
1) Constructor name should be same as class name.
2) If you don't define a constructor for a class,
a default parameterless constructor is automatically
created by the compiler.
3) The default constructor calls super() and initializes all
instance variables to default value like 0, null.
4) If we want to parent class constructor, it must be called in
first line of constructor.
(A) 1
(B) 1, 2
(C) 1, 2 and 3
(D) 1, 2, 3 and 4
Answer: (D)
Explanation:
Quiz of this Question
Recommended Posts:
- Java | Constructors | Question 1
- Java | Constructors | Question 2
- Java | Constructors | Question 4
- Java | Constructors | Question 5
- Java | Constructors | Question 6
- Java | Constructors | Question 8
- Why Constructors are not inherited in Java?
- Order of execution of Initialization blocks and Constructors in Java
- C++ | Constructors | Question 2
- C++ | Constructors | Question 3
- C++ | Constructors | Question 4
- C++ | Constructors | Question 5
- C++ | Constructors | Question 6
- C++ | Constructors | Question 7
- C++ | Constructors | Question 8
- C++ | Constructors | Question 9
- C++ | Constructors | Question 10
- C++ | Constructors | Question 17
- C++ | Constructors | Question 12
- C++ | Constructors | Question 13

