Abstract class can have one abstract method at miminum.
All methods in Interface should be abstract, so user has to implement all methods when he implements an interace.
here is my example
------
//test.java
class test
{
public static void main(String args[])
{
human Peter = new human();
Peter.playingRPG();
}
}
------
//human.java
class human extends hominoidea implements playingComputer
{
void eating()
{
System.out.println("Use spoon or chopstick to eat"
}
public void icq()
{
System.out.println("start icq"
System.out.println("Find who is online"
System.out.println("chat with your friend"
}
public void playingRPG()
{
System.out.println("start the game"
System.out.println("Load a save"
System.out.println("go to a town"
}
}
------
//playingComputer.java
public interface playingComputer
{
public abstract void icq(); // abstract can be omitted here because method is supposed to be abstract in interface
public void playingRPG();
}
------
//hominoidea.java
abstract class hominoidea
{
void walkWithFourLeg()
{
System.out.println("walking"
}
abstract void eating();
}
------
Why some of these questions sound like uni/college asignments questions from students that can not be bother to look up the answer? Any introductory Java book would have provided an answer to question on this thread!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.