// Java program to overload constructors
public class Person {
// two member variables
String name = "Pikachu";
int age = 10;
// the driver method
public static void main( String args[ ] ) {
Person p1 = new Person( );
Person p2 = new Person( "Ash", 13 );
p1.display( );
}
// a default constructor
Person( ) { }
// a two-argument constructor
Person( String n, int a ) { name = n; age = a; }
// a method
void display( ) { System.out.println( name + " " + age ); }
}
|