Suppose we are having the one already existing class, we call it as “Parent Class”. Suppose we need to create another class having exactly same attributes to that of the parent class and some extra attributes then we use “extend” keyword to extend the class.
Extends Keyword :
We can extend a class by using the extends keyword in a class declarationafter the class name and before the parent class.
public class ParentClass { }
and we define child class like shown below –
public class ChildClass extends ParentClass { }
Type | Name | Explanation |
---|---|---|
Super Class | ParentClass | The class from which another class is derived is called the superclass |
Sub Class | ChildClass | The derived class (the class that is derived from another class) is called a subclass |
Important Note : Extends Keyword
- In the Java All the classes are child classes of java.lang.Object
- Object is the Super Class of all the classes in Java
- Like C++ multiple inheritance is not allowed in Java. Class can only extend one class.
0 comments:
Post a Comment
Let us know your responses and feedback