Inheritance is one of the features of Object Oriented Programming(OOPs). It is a mechanism in which an object acquires all the properties of its parent object. Inheritance allows one class to use variables and methods of other class.The derived class is called subclass and the base class is called as super-class. The derived class can have its own variables and methods.
Inheritance is a compile-time mechanism. A super-class can have any number of sub classes. But a subclass can have only one super-class. This is because Java does not support multiple inheritance.
The extends keyword indicates that you are making a new class that derives from an existing class. The meaning of "extends" is to increase the functionality.
Inheritance represents the IS-A relationship, also known as parent-child relationship.
Syntax:
class Subclass-name extends Superclass-name
{
//methods and fields
}
{
//methods and fields
}
The extends keyword indicates that you are making a new class that derives from an existing class. The meaning of "extends" is to increase the functionality.
No comments:
Post a Comment