Super class, sub classes in inheritance in Java: extends keyword

When a class is inherited, the parent class is known as the super class in Java and the child class is known as sub class. Sub class inherits properties of its super class and adds few of its own. Extends keyword is used for defining a sub class. However, the members which are declared as private by the¬†super class¬†can’t be accessed by the subclass.


class superclass_name{

body of superclass;

class subclass_name extends superclass_name {

body of subclass;



For Example: Here, Test class cannot access the c because it is private to Myclass.

class Myclass {

int a, b;

private int c;


class Test extends Myclass {

int d;



Leave a Reply