java methods in inheritance tutorial

java methods inheritance tutorial in this topic we will discuss in details about fields and methods in inheritance.

The topic is well covered by bodhak expert tutors. Topics are covered in detail of the concept. All The concepts are explained by syntax and example programs.

 

 

java methods inheritance tutorial

About fields in inheritance:

The inherited fields can be used directly, just like any other fields.

You can declare new fields in the subclass that are not in the superclass

You can declare a field in the subclass with the same name as the one in the superclass, thus hiding it (not recommended).

A subclass does not inherit the private members of its parent class.

However, if the super class has public or protected methods for accessing its private fields, these can also be used by the subclass

About methods in inheritance:

The inherited methods can be used directly as they are.

The new instance method in the subclass that has the same signature as the one in the superclass, thus overriding it.

You can write a new static method in the subclass that has the same signature as the one in the superclass, thus hiding it.

New methods can be declared in the subclass that is not in the superclass.

About super keyword:

The super keyword is associated with Inheritance. Inheritance is a concept of Object Oriented Programming wherein the subclass inherits characteristics and properties of the super class. The base class is also called as a superclass.

Usage of super Keyword

The super is used to refer immediate parent class instance variable.

it is also used to refer parent class methods.

super() is used to invoke immediate parent class constructor.

It is used inside a sub-class method definition to call a method defined in the superclass. Private methods of the superclass cannot be called. Only public and protected methods can be called by the super keyword.

It is also used by class constructors to invoke constructors of its parent class.