Session 12 - Java Interface
Session 12 - Java Interface
interface Language {
public void getType();
interface B {
// members of B
}
class C implements A, B {
// abstract members of A
// abstract members of B
}
Extending an Interface
interface Line {
// members of Line interface
}
// extending interface
interface Polygon extends Line {
// members of Polygon interface
// members of Line interface
}
Extending Multiple Interfaces
interface A {
...
}
interface B {
...
}
interface C extends A, B {
...
}
Interfaces are also used to achieve multiple inheritance in
Java.
interface Line {
…
}
interface Polygon {
…
}
// by default public
void getName();
}
interface SecondInterface {
public void myOtherMethod(); // interface method
}
class Main {
public static void main(String[] args) {
DemoClass myObj = new DemoClass();
myObj.myMethod();
myObj.myOtherMethod();
}
}
Java Varargs
Varargs is a short name for variable arguments.
In Java, an argument of a method can accept arbitrary
number of values. This argument that can accept variable
number of values is called varargs.