Exercise - 4
a). Write a JAVA program to implement constructor overloading.
class Student
{
int height=167;
int weight=78;
String course="Intermediate";
int rollno=225;
Student()
{
System.out.println("Inside of the First Method");
System.out.println("Height="+height+"CM");
System.out.println("Weight="+weight+"KG");
System.out.println("Course with year:"+course);
System.out.println("Roll NO:"+rollno);
}
Student(double marks)
{
System.out.println("Inside of the Second Method");
System.out.println("Marks percentage:"+marks);
}
}
class Biodata
{
public static void main(String args[])
{
Student s1=new Student();
Student s2=new Student(92.56);
}
}
b). Write a JAVA program implement method overloading.
class Details
{
String name="Vivo-Y87";
int storage=64;
String cameratype="Dual Camera";
public void performance(int ram)
{
System.out.println("Inside of the 1st Method.......");
System.out.println("Name of the Mobile is:"+name);
System.out.println("Internal Storage of the Mobile is:"+storage+"GB");
System.out.println("Ram of the Mobile is:"+ram+"GB");
System.out.println("Camera type of the Mobile is:"+cameratype);
}
public void performance(String os,double version)
{
System.out.println("Inside of the 2nd Method....");
System.out.println("The os of the mobile is:"+os);
System.out.println("Version of the mobile is:"+version);
}
}
public class Mobile
{
public static void main(String args[])
{
System.out.println("The Mobile Details are:");
Details d=new Details();
d.performance(8);
d.performance("Android",8.10);
}
}
a). Write a JAVA program to implement constructor overloading.
class Student
{
int height=167;
int weight=78;
String course="Intermediate";
int rollno=225;
Student()
{
System.out.println("Inside of the First Method");
System.out.println("Height="+height+"CM");
System.out.println("Weight="+weight+"KG");
System.out.println("Course with year:"+course);
System.out.println("Roll NO:"+rollno);
}
Student(double marks)
{
System.out.println("Inside of the Second Method");
System.out.println("Marks percentage:"+marks);
}
}
class Biodata
{
public static void main(String args[])
{
Student s1=new Student();
Student s2=new Student(92.56);
}
}
b). Write a JAVA program implement method overloading.
class Details
{
String name="Vivo-Y87";
int storage=64;
String cameratype="Dual Camera";
public void performance(int ram)
{
System.out.println("Inside of the 1st Method.......");
System.out.println("Name of the Mobile is:"+name);
System.out.println("Internal Storage of the Mobile is:"+storage+"GB");
System.out.println("Ram of the Mobile is:"+ram+"GB");
System.out.println("Camera type of the Mobile is:"+cameratype);
}
public void performance(String os,double version)
{
System.out.println("Inside of the 2nd Method....");
System.out.println("The os of the mobile is:"+os);
System.out.println("Version of the mobile is:"+version);
}
}
public class Mobile
{
public static void main(String args[])
{
System.out.println("The Mobile Details are:");
Details d=new Details();
d.performance(8);
d.performance("Android",8.10);
}
}
No comments:
Post a Comment