Joke Collection Website - Public benefit messages - Using java polymorphism, interface and abstract class to define a tablet computer with mobile phone function.

Using java polymorphism, interface and abstract class to define a tablet computer with mobile phone function.

Hello, I'm glad to answer your question:

First, define the interface: two moving methods (call, sendMessage).

Public interface mobile device (

Publicovoid call ();

public void sendMessage();

}

Then define the abstract class pad to realize the mobile interface (because the tablet has the function of a mobile phone).

The public abstract class Pad realizes mobile (

//Implement the called function.

Public void call () {

System.out.println ("made a phone call");

}

//What about the text message?

Public void sendMessage() {

System.out.println ("send short message");

}

//Add a virtual method for surfing the Internet.

Public abstract void net ();

//Add virtual methods to play games.

Public abstract void playgame ();

}

//The real tablet computer (Ipad) inherits all the functions of pad and realizes online games.

Public Ipad expansion board (

@ Overlay

Public void network () {

System.out.println ("online and offline");

}

@ Overlay

public void playGame() {

System.out.println ("played a game");

}

}

The above code, in which Mobile is the interface. Pad is an abstract class, and the following are polymorphic:

Public static void main(String[] args) {

Pad pad = new iPad ();

pad . network();

}

I hope my answer can help the landlord! thank you