preview

Lesson 5 : Inheritance : Learning Objectives And Outcomes

Satisfactory Essays

LESSON 5: INHERITANCE LEARNING OBJECTIVES AND OUTCOMES • Introduction • Extending a Class • Defining a subclass • Subclass constructor • Multilevel inheritance • Hierarchical inheritance INTRODUCTION Inheritance is a feature by which a class acquires attributes of another class. Inheritance makes “Code Reusability” property applicable. The class that provides its attributes is known as the base class and the class that accepts those attributes is known as a derived class. It permits programmers to enhance their class without reconstructing it. Hence, an object of a derived class can use the accessible properties of the base class without defining it in the derived class. EXTENDING A CLASS The Inheritance property of JAVA allows subclasses for inheriting all the variables and methods of the parent classes. It has following forms: • Single inheritance (only one super class) • Multiple inheritance (several super class) • Hierarchical inheritance (one super class, many subclasses) • Multilevel inheritance (Derived from a derived class) JAVA uses secondary inheritance path in the form of interfaces to implement multiple inheritance. DEFINING A SUBCLASS The syntax of Subclass is: Class subclassname extends superclassname { Variables declaration: Methods declaration: } Extends keyword signifies that the properties of the superclassname are extended subclassname. Programe: Class Room { int len; int brth; Room (int a, int b) { len = a; brth = b; } int area ( )

Get Access