Screenshot 2024-02-26 164935.png

here

class User

is defined. Now we define constructor

User(String username, int age)

inside this class. Constructor defines the arguments which are to be passed to the object/instance during invoking the class.

Inheritance

One class can inherit from other.

Screenshot 2024-02-26 181104.png

Screenshot 2024-02-26 181119.png

Screenshot 2024-02-26 181128.png

The class User( ) is written before. Now another class SuperUser( ) extending/inheriting class User is defined. Now before writing the line:

SuperUser(String username, int age) : super(username, age);

the following error shows:

Screenshot 2024-02-26 181703.png

For this we define the constructor and assign the same arguments as the parent class, by using super( ). [super is a keyword].

Also in the extended class SuperUser, we define an additional function publish(), exclusively for this class, (not the parent one).