UNIT-3 (Oops Using Java)
UNIT-3 (Oops Using Java)
• Inheritance
• Types of Inheritance
• Super Keyword
• Abstract Classes
• Method Over ridding
• Interfaces
• Packages Presented by
G. Mahesh
Assistant Professor
Bapatla Engineering College
INHERITANCE
• Inheritance is the mechanism of deriving new
class from old one, old class is known as super
class and new class is known as sub class.
• The sub class inherits all of its instances
variables and methods defined by the super
class. Thus we can say that subclass is
specialized version of super class.
Cont…..
The sub class derives super class using the keyword
extends.
Syntax:
Class base
{
Data members;
Member functions;
}
Class derived extends base
{
}
Cont…..
• When the derived class extends base, the
derived class takes the properties from base
and we can access that properties of base
through the object of derived.
derived obj=new derived();
obj.data members;
obj.member functions();
Cont…..
Benefits of Java’s Inheritance
• Reusability of code
• Code Sharing
Classes
B C
Reusability: As the name specifies,
reusability is a mechanism which facilitates
you to reuse the fields and methods of the
existing class when you create a new class.
You can use the same fields and methods
already defined in the previous class.
interface <interface name>
{
// declare constant fields
//declare methods that abstract
// by default.
}
Internal addition by the compiler