Docsity

Multilevel Inheritance in Java programming, Study notes of Object Oriented Programming

Partial preview of the text

Download Multilevel Inheritance in Java programming and more Study notes Object Oriented Programming in PDF only on Docsity!

By- Ms. Aquilla Afonso

Assistant Professor

St. Xavier’s College-Mapusa-

Goa

MULTILEV EL INHERITA NCE

Multilevel Inheritance :

In Multilevel

Inheritance, a derived

class will be inheriting

a base class and as

well as the derived

class also act as the

base class to other

class. In below image,

the class A serves as

a base class for the

derived class B, which

in turn serves as a

base class for the

derived class C.

real world program class Customised_Belt_Watch extends Wrist_Watch { String material="Silicone"; String color="Blue"; //add a variable and perform calc rs. public void data_info() { System.out.println("Belt Material: "+material+"\nBelt color: "+color); //add prices } } class Wrist_Watch { String type="Wrist watch"; String display="Analogue"; //add a variable price= public void getdata() { System.out.println("Wa tch type: "+type+" nWatch Display:

real world

program

class

Customised_Bracelet_Wat

ch extends

Customised_Belt_Watch

int no_of_bracelets=2;

//add a variable and

perform calc

public void display_data()

System.out.println("Num

ber of Bracelets:

"+no_of_bracelets);

public class Multilevel { public static void main(String[] args) { Customised_Belt_Watch b=new Customised_Belt_Watch(); System.out.println("CUSTOMISED BELT WATCH"); b.getdata(); b.data_info(); Customised_Bracelet_Watch c= new Customised_Bracelet_Watch(); System.out.println("\nCUSTOMISED BRACELETS WITH WATCH"); c.getdata(); c.data_info(); c.display_data();