Friday, 26 June 2015

Constructor


public class Lab586 {
public static void main(String[] args) {
Student stu1=new Student();
stu1.show();
Student stu2=new Student();
stu2.show();
}
}



public class Lab587 {
public static void main(String[] args) {
Student stu=new Student();
stu.sid=99;
stu.sname="Srinivas";
stu.show();    
}
}



public class Lab588 {
public static void main(String[] args) {
Student stu=new Student();
stu.sid=88;
stu.sname="Dande";
stu.show();
}
}



public class Lab589 {
public static void main(String[] args) {
Student stu=new Student();
stu.sid=77;
stu.sname="Srinivas";
stu.show();
}
}



public class Lab590 {
public static void main(String[] args) {
Student stu1=new Student(88,"Srinivas");
stu1.show();
Student stu2=new Student(99,"Dande");
stu2.show();
}
}



public class Lab591 {
public static void main(String[] args) {
Student stu1=new Student();
stu1.show();
Student stu2=new Student(55,"Dande");
stu2.show();
}
}



public class Lab592 {
public static void main(String[] args) {
Student stu1=new Student(99,"Sri","sri@jlc",9999);
stu1.show();
Student stu2=new Student(88,"Vas","vas@jlc");
stu2.show();
Student stu3=new Student(77,"SD");
stu3.show();
Student stu4=new Student();
stu4.show();
}
}



public class Lab597 {
public static void main(String[] args) {
Student stu=new Student(77,"SD");
stu.show();
}
}

public class Student {
int sid;
String sname;
String email;
long phone;
public Student(int id, String sn, String em, long ph) {
System.out.println("4Args Constructor");
sid = id;
sname = sn;
email = em;
phone = ph;
}
public Student(int id, String sn, String em) {
System.out.println("3Args Constructor");
sid = id;
sname = sn;
email = em;
}
public Student(int id, String sn) {
System.out.println("Student 2args constructor");
sid = id;
sname = sn;
}

public Student() {
System.out.println("Default Constructor");
}

void show(){
System.out.println(sid+"\t"+sname);
}
}

No comments:

Post a Comment