0% found this document useful (0 votes)
14 views6 pages

Prac 18

Uploaded by

Payal Jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views6 pages

Prac 18

Uploaded by

Payal Jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Program to implement single inheritance.

class parent

int a=10;

int b=20; void

add()

int c=a+b;

System.out.println("Addition="+c);

class child extends parent

void sub()

int c=a-b;

System.out.println("Subtsraction = "+c);

public static void main(String args[])

child c=new child();

c.add();

c.sub();

}
Program to implement multilevel inheritance.
class Continent

void display(String a)

System.out.println("Continent = "+a);

class Country extends Continent

void display1(String a)

System.out.println("Country = "+a);

class State extends Country

void display2(String a)

System.out.println("State = "+a);

class District extends State

void display3(String a)

System.out.println("District = "+a);
}

class Taluka extends District

void display4(String a)

System.out.println("Taluka = "+a);

class Address

public static void main(String args[])

Taluka t=new Taluka();

t.display("Asia");

t.display1("India");

t.display2("Maharashtra");

t.display3("Pune");

t.display4("Bhor");

}
Develop a program to calculate the room area and volume to
illustrate the concept of single inheritance.
class Room

double l=7.7;

double b=10.5;

double h=12.4;

class Measure extends Room

void area()

double a=2*(l*b+b*h+h*l);

System.out.println("Area of the Room = "+a);

void volume()

double v=l*h;

System.out.println("Volume of the Room = "+v);

}
}

class Result

public static void main(String args[])

Measure m=new Measure();

m.area();

m.volume();

You might also like