10.1) A) DEMONSTRATE USE AT LEAST TWO CONSTRUCTORS. PROGRAM: class emp { String name; int rollno;
emp(String s,int i) { name=s; rollno=i; } void display() { System.out.println("name:"+name); System.out.println("rollno:"+rollno); } } class empdemo { public static void main(String args[]) { emp e=new emp("Meer",1210); e.display(); } }
OUTPUT:
B) PROGRAM: import java.util.*; class stud {
String name; int rollno;
Scanner s=new Scanner(System.in);
stud() { System.out.println("Name:"); name=s.nextLine(); System.out.println("rollno:"); rollno=s.nextInt(); } void display() { System.out.println("name:"+name); System.out.println("rollno:"+rollno);
} } class studDemo { public static void main(String args[]) {
stud s=new stud(); s.display(); } }
OUTPUT:
10.2) DEVELOP A PROGRAM OF ADDDITION OF TWO COMPLEX NUMBER USING CONSTRUCTOR OVERLOADING . PROGRAM: class complex { int real,img; float real1,img1;
complex(int r,int i) { real=r; img=i; } complex(float r,float i) { real1=r; img1=i; } void display() { System.out.println("Equation1"+real+"+"+img+"i"); } void display1() { System.out.println("Equation2"+real+"+"+img+"i"); } void sum(float r,float i) { System.out.println("sum="+r+"+"+i+"i");
} } class complexDemo { public static void main(String args[]) { complex c1=new complex(1,2); complex c2=new complex(1.0f,2.0f);
float r,i; r=c1.real+c2.real; i=c1.img+c2.img;
c1.display(); c2.display(); c1.sum(r,i); r=c1.real+c2.real1; i=c1.img+c2.img1; } }
OUTPUT: