Example of default constructor that displays the default values?
In the below class,you are not creating any constructor so compiler provides you a default constructor.Here 0 and null values are provided by default constructor.
package com.mindclues;
class DefaultConstructor {
int id;
String name;
void display() {
System.out.println("Default value of int (id) "+id);
System.out.println("Default value of String(name) "+name);
}
public static void main(String args[]) {
DefaultConstructor s1 = new DefaultConstructor();
DefaultConstructor s2 = new DefaultConstructor();
s1.display();
s2.display();
}
}
Default value of int (id) 0 Default value of String(name) null Default value of int (id) 0 Default value of String(name) null




post a comment