What is the purpose of a default constructor?
Short Answer
Views 1142
Answer:
The default constructor is used to provide the default values to the object like 0, null, etc., depending on the type.
Example of default constructor that displays the default values
//Let us see another example of default constructor //which displays the default values class Student3{ int id; String name; //method to display the value of id and name void display(){System.out.println(id+" "+name);} public static void main(String args[]){ //creating objects Student3 s1=new Student3(); Student3 s2=new Student3(); //displaying values of the object s1.display(); s2.display(); } }
0 null 0 null
Related Articles:
This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.
Join Our telegram group to ask Questions
Click below button to join our groups.