Default constructor in java example 2
Java Programming Language Class, Object and Methods in java (Article) Class, Object and Methods in java (Program)
1207Program:
class DefaultConstructor{ int id; String name; float age; DefaultConstructor(){ System.out.println(id+" "+name+" "+age); } public static void main(String args[]){ DefaultConstructor s1=new DefaultConstructor(); DefaultConstructor s2=new DefaultConstructor(); } } /* Default constructor provides the default values to the object like 0, null etc. depending on the type. */
Output:
0 null 0.0 0 null 0.0 Press any key to continue . . .
This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.