You are on page 1of 11

1.

Write a java program to create a parent class as”Teacher” and in the


Teacher class display subject as “math”,”science”,”English”.Simillarly create a
derive class “PhysicsTeacher” and access the subject teches by the Physics
teacher ’Mechanics’ and ‘Thermodynnamics’ and display all the subject?
import java.util.*;
import java.io.*;
class Teacher
{
public String Math;
public String English;
public String Science;
public String PhysicsM;
public String PhysicsT;
public void getdata()
{
Scanner Sc=new Scanner(System.in);
System.out.println("Enter the Topic of Math:");
Math=Sc.next();
System.out.println("Enter the Topic of the English:");
English=Sc.next();
System.out.println("Enter the Topic of the Science:");
Science=Sc.next();
}
public void display()
{
System.out.println("Teacher class is executed");
System.out.println("Subject of the math is="+Math);
System.out.println("Subject of the English is="+English);
System.out.println("Subject of the Science is="+Science);
}
}
class PhyTeacher extends Teacher
{
void getdata1()
{
Scanner Sc=new Scanner(System.in);
String[] input=new String[2];
System.out.println("Enter the 2 subject Teaches by phy teacher:");
input=Sc.nextLine().split(" ");
PhysicsM=input[0];
PhysicsT=input[1];
}
int putdata()
{
System.out.println("Physics teacher class executed");
System.out.println("Two subject teches by phy teacher="+PhysicsM+" and "+PhysicsT);
return 1;
}
}
class sona
{
public static void main(String args[])
{
Teacher T=new Teacher();
PhyTeacher P=new PhyTeacher();

T.getdata();

P.getdata1();

T.display();

P.putdata();

System.out.println("CALL BY CHILD CLASS OBJECT");


P.putdata();

2.Write a program inn java,to create 4 classes as


‘Vehicle’,’car’,’Bike’,’Scouter’.Declare “Vehicle” class is the parent class and
display properties as ‘Stearing time’,’model no’,’company name’.Simillary
define other classes bike,scouter,car and construct hierarchical class display
inherited properties according to yourself?
import java.util.*;

import java.io.*;

class Vehicle

public double Stime;

public String model_no;

public String company_name;

public void display()

System.out.println("Vehicle class execute:");


execute:")

}
class Bike extends Vehicle

void getdata()

Scanner Sc=new Scanner(System.in);

System.out.println("Enter the Model no:");

model_no=Sc.next();

System.out.println("Enter the Stearing time for bike:");

Stime=Sc.nextInt();

System.out.println("Enter the Company name of the bike:");

company_name=Sc.next();

void putdata()

System.out.println("Bike class execute:");

System.out.println("Stearing time:"+Stime);

System.out.println("Model no:"+model_no);

System.out.println("Company name:"+company_name);

class Scouter extends Vehicle

void getdata()

Scanner Sc=new Scanner(System.in);

System.out.println("Enter the Model no:");

model_no=Sc.next();

System.out.println("Enter the Stearing time for scouter:");

Stime=Sc.nextInt();

System.out.println("Enter the Company name of the scouter:");

company_name=Sc.next();
}

void putdata()

System.out.println("Scouter class execute:");

System.out.println("Stearing time:"+Stime);

System.out.println("Model no:"+model_no);

System.out.println("Company name:"+company_name);

class Car extends Vehicle

void getdata()

Scanner Sc=new Scanner(System.in);

System.out.println("Enter the Model no:");

model_no=Sc.next();

System.out.println("Enter the Stearing time for car:");

Stime=Sc.nextInt();

System.out.println("Enter the Company name of the car:");

company_name=Sc.next();

void putdata()

{ System.out.println("car class execute:");

System.out.println("Stearig time:"+Stime);

System.out.println("Model no:"+model_no);

System.out.println("Company name:"+company_name);

class sonali

public static void main(String args[])


{

Vehicle ob=new Vehicle();

Bike B=new Bike();

Scouter S=new Scouter();

Car C=new Car();

B.getdata();

C.getdata();

S.getdata();

B.putdata();

C.putdata();

S.putdata();

System.out.println("called by object of parent class");

ob.display();

System.out.println("call by child object");

C.display();

}
3.wap to implement a parent class as grandmother where properties are
hobbies,athletician,artist and musician.construct these properties into four
level of classes?
import java.util.*;

import java.io.*;

class Grandmother

String complex;

String name;

String musician;

String artist;

String atheletician;

String Mname;

String Mmusician;

String Martist;

String Matheletician;

void input()

Scanner Sc=new Scanner(System.in);

System.out.println("Enter the GRANDMOTHER Name:");

name=Sc.next();

System.out.println("Enter the musician hobbies of grandmother");

musician=Sc.next();

System.out.println("Enter the artist character:");

artist=Sc.next();

System.out.println("Enter the Atheletician character:");

atheletician=Sc.next();

void display()

System.out.println("Name of grandmother="+name);
System.out.println("She is Atheletician as ="+atheletician);

System.out.println("She is Artist as="+artist);

System.out.println("She is Musician as a="+musician);

class Mother extends Grandmother

String Dname;

String Dmusician;

String Dartist;

String Datheletician;

void input()

Scanner Sc=new Scanner(System.in);

System.out.println("Enter the MOTHER Name:");

Mname=Sc.next();

System.out.println("Enter the musician hobbies of mother");

Mmusician=Sc.next();

System.out.println("Enter the artist character:");

Martist=Sc.next();

System.out.println("Enter the Atheletician character:");

Matheletician=Sc.next();

void display()

System.out.println("Name of mother="+Mname);

System.out.println("She is Atheletician as ="+Matheletician);

System.out.println("She is Artist as="+Martist);

System.out.println("She is Musician as a="+Mmusician);

}
class Daughter extends Mother

String Gname;

String Gmusician;

String Gartist;

String Gatheletician;

void input()

Scanner Sc=new Scanner(System.in);

System.out.println("Enter the Daughter Name:");

Dname=Sc.next();

System.out.println("Enter the musician hobbies of Daughter");

Dmusician=Sc.next();

System.out.println("Enter the artist character:");

Dartist=Sc.next();

System.out.println("Enter the Atheletician character:");

Datheletician=Sc.next();

void display()

System.out.println("Name of Daughter="+Dname);

System.out.println("She is Atheletician as ="+Datheletician);

System.out.println("She is Artist as="+Dartist);

System.out.println("She is Musician as a="+Dmusician);

class Granddaughter extends Daughter

void input()

Scanner Sc=new Scanner(System.in);


System.out.println("Enter the GRANDDaughter Name:");

Gname=Sc.next();

System.out.println("Enter the musician hobbies of granddaughter");

Gmusician=Sc.next();

System.out.println("Enter the artist character:");

Gartist=Sc.next();

System.out.println("Enter the Atheletician character:");

Gatheletician=Sc.next();

void display()

System.out.println("Name of grandmother="+Gname);

System.out.println("She is Atheletician as ="+Gatheletician);

System.out.println("She is Artist as="+Gartist);

System.out.println("She is Musician as a="+Gmusician);

class sonu

public static void main(String args[])

Grandmother G=new Grandmother();

Mother M=new Mother();

Daughter D=new Daughter();

Granddaughter Gd=new Granddaughter();

G.input();

G.display();

M.input();

M.display();

D.input();

D.display();
Gd.input();

Gd.display();

Name-sonali Satapathy
Regdno-1806151014

You might also like