You are on page 1of 2

Object Oriented Programming Practical

Exercise 7

Exercise 7

Implementation of Inheritance

Objective: This exercise enables you to understand the concept of implementation of inheritance in Java. Procedure: This program demonstrates the implementation of inheritance concepts through classes. Algorithm: The algorithm for the program is given below: /* When you want to create a new class and there is already a class that includes some of the code that you want, you can derive your new class from the existing class. In doing this, you can reuse the fields and methods of the existing class without having to write (and debug!) them yourself. A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass.

*/ Step 1: Open a new text document on your desktop. Step 2: Write the following code in the main function: 2.1: Define a superclass or a parent class. e.g. Birds

Sikkim Manipal University

Page No.: 8

Object Oriented Programming Practical

Exercise 7

2.2: Define the member variables of the subclass such as color, wings, etc. 2.3: Define the member functions for the subclass such as display() in the main class. 2.4: Define the subclasses as flying and non-flying birds and add appropriate member variables and methods. 2.5: Try to use some of the member functions and variables of the superclass in the subclasses. Step 3: Print the outputs from the functions of the superclass and subclasses on the console.

Sikkim Manipal University

Page No.: 9

You might also like