Multiple inheritance with class and interface

In this blog, we will see one sub class extends with super class and implements with interface. This is multiple inheritance structure in java programs.

Multiple inheritance structure

Super Class                            Interface

| [extends]                              | [implements ]

——————————————

|

Sub Class

 


Inter1 in InterPack1 package

package InterPack1;

public interface Inter1   // Interfaces

{

                public int x = 10;                // it’s final variable          

                public void method1();  // Indexing | Only Dec

}


SuperClass in clExample Package

package clExample;

public class SuperClass

{

                public void methodSuper()

                {

                                String name[] = {“A”,”B”,”C”,”D”,”E”};

                                for(int i=0;i<name.length;i++)

                                {

                                                System.out.println(name[i]);

                                }

                }

}


Class D in classStore Package

package classStore;

import clExample.*;

import InterPack1.*;

// Note : must extends class 1st then implements interface

public class D extends SuperClass implements Inter1

{

                public void method1()

                {

                                System.out.println(“Inter1”);

                }

                public void methodD()

                {

                                System.out.println(“Welcome in D Class”);

                }

}


Class Example4 in mainPackage

package mainPackage;

import classStore.D;

public class Example4

{

                public static void main(String[] args)

                {

                                // Create D Class object for all method access

                                D obj = new D();

 

                                obj.method1(); // interface method

                                obj.methodD();                // own class method

                                obj.methodSuper(); // super class method

                }

}


Output:

Inter1

Welcome in D Class

A

B

C

D

E


Video available on YouTube.

 


[sbscrbr_form]

If you have any query on blog example, you can directly comment us or subscribe our website


Earn Money Online

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

638total visits,7visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

Enter Captcha Here :*

Reload Image

EmailEmail
PrintPrint