0% found this document useful (0 votes)
14 views2 pages

Interface Extends in Java

Uploaded by

Dhavan Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Interface Extends in Java

Uploaded by

Dhavan Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

interface:

* abstract class
* abstract methods
* final variables(constants)
* static methods(must have body)
* abstract methods must override in sub class
* should use "public" access modifier.

public interface A {
//final fields
int x=20;
void show();//abstract method
static void display() {

}
}

How to implement Multiple inheritance?


* one sub class can have two or more super classes

interface A{
void show();
}

interface B{
void sum();
}

public class Addition implements A, B {


int x,y,res;
Addition(int x,int y){
this.x=x;
this.y=y;
}
@Override
public void sum() {
this.res=this.x+this.y;

@Override
public void show() {
System.out.println(this.res);

public class Main {

public static void main(String[] args) {


Addition add=new Addition(10,20);
add.sum();
add.show();
}

}
Rule:
if sub class has no super class and implement super interfaces.

interface A{
}
interface B{
}

class C implements A,B{


}

if sub class must ineherit to a class and two interfaces,then use extends first and
them implements.

class D{

}
interface A{
}
interface B{
}

class C extends D implements A,B{

You might also like