Inheritance and Interfaces


Inheritance and Interfaces

What Is Inheritance?

Inheritance can be defined as the process where one class acquires the properties (methods and fields) of another. With the use of inheritance the information is made manageable in a hierarchical order.

Syntax:

class Demo extends Parent {

// new fields and methods defining 
// a sub class will go here

}

What Is an Interface?

An interface is a device or a system that unrelated entities use to interact.

Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. source

There are mainly three reasons to use interface. They are given below.

  1. It is used to achieve abstraction.
  2. By interface, we can support the functionality of multiple inheritance.
  3. It can be used to achieve loose coupling.

Syntax:

interface {

// declare constant fields  
// declare methods that abstract   
// by default.   }  

   

Get back to EMAM’S HOMEPAGE

I have created this page as a part of my project using Github, Please visit my profile, I will be more than happy to hear from you all.                       © Emam Shararah 2021