Friday, May 7, 2021

INHERITANCE or SUPER KEYWORD (Experience In JAVA)

 INHERITANCE 

Inheritance is as important characteristic of Object-oriented programming by which we can define a new class from an extends class in such a way that the new class will acquire all the public and protected properties of extends class.

The new class can also add their properties, the extended class known as the superclass or parent class, and the new class known as subclass and child class.

Inheritance provides the facility of code reusability if you use inheritance then the program flow is generic to specify.

Note: java only support a public inheritance that means the visibility mode of the inheritance properties into sub-class, public properties of the superclass become public properties of sub-class and protected properties of superclass become protected properties sub-class.

There are two steps to make a program using inheritance

  1. Superclass definitions:- Superclass definitions  is same as normal class definitions in which we have to declared and define all properties of the class also have specific there visibility mode.
  2. Sub-class definitions:-In we have to specify the superclass with help of extends keyword.

There are five types of Inheritance in java.

·        Simple Inheritance
·        Multiple Inheritance
·        Hierarchical Inheritance
·        Multilevel Inheritance
·        Hybrid Inheritance

 

Videos Link for program:- coming soon.

SUPER KEYWORD

The super keyword is a special type of keyword which may be used in following way according to our requirement

  • To access the instance variable superclass
  • To access the member method of the superclass
  • To access the constructor of the superclass

 To access the instance variable superclass

When the name of an instance variable of a superclass and a subclass is the same then to access the instance variable of superclass we must have to use the “super” keyword.

Example.


To access the member method of super class

When the name of a method of a super class and a sub class is same then to access the method of super class we have to use “super” keyword

Example.


To access the constructor of superclass.

Whenever we create an object of a sub class then the default constructor of the super class called implicitly. Constructor is executed from top to bottom but not reverse. If there is no default constructor then complier will produce a compilation error. “SUPER” keyword is used to access the required constructor of the super class .if super keyword is not given then the control is looking for default constructor.

Example.








No comments:

INTRODUCTION TO COMPUTER NETWORKS

A Computer network consists of two or more autonomous computers that are linked (connected) together in order to: • Share resources (files...