A class can only have one parent class but can implement several interfaces
|
interfaces are essentially abstract classes and can have methods without impementation and static variables
|
interface Printable {
-
void print();
-
void print(String str);
|
}
|
class Cookie implements Printable {
-
void print() {
-
System.out.println("Cookie");
-
}
|
}
|
class WastePaper implements Printable {
-
void print(String str) {
-
int i,len=str.length();
-
for(i=0; i < len; i++) {
-
singlechar = str.charAt(i);
-
System.out.println("This is character No." + i + " " + singlechar);
-
}
-
}
|
}
|