Level 1 & 2 More Programs

This commit is contained in:
2021-06-07 10:35:48 +05:30
parent 688319db00
commit f56d525b45
9 changed files with 204 additions and 3 deletions

23
ChainConstructor.java Normal file
View File

@@ -0,0 +1,23 @@
// Write a program in java to demonstrate chain constructor.
public class ChainConstructor {
int a, b;
public ChainConstructor( ) {
this(3);
System.out.println("Default");
}
public ChainConstructor (int x) {
this(x, 2);
System.out.println("with one arg");
}
public ChainConstructor(int x, int y) {
a=x;
b=y;
System.out.println("with two args");
}
public static void main(String arg[]) {
ChainConstructor p=new ChainConstructor( );
ChainConstructor q=new ChainConstructor(8);
ChainConstructor r = new ChainConstructor(8,7);
}
}