World's most popular travel blog for travel bloggers.

Extends Keyword in java

, , No Comments
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 {
}
TypeNameExplanation
Super ClassParentClassThe class from which another class is derived is called the superclass
Sub ClassChildClassThe derived class (the class that is derived from another class) is called a subclass

Important Note : Extends Keyword

  1. In the Java All the classes are child classes of java.lang.Object
  2. Object is the Super Class of all the classes in Java
  3. 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