Package test05;
public class Duotai_test {
/**
* One object, multiple forms
* wqq→student, Worker, Friend
1), an object, multiple forms (types).
The same object, in different situations, shows different roles.
Different roles, can achieve different functions.
In this way, an object is required to correspond to multiple patterns,
are often implemented using a class implementation (multiple) interface.
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated method stubs
WQQ wqq=new wqq ();///Specific one object
Abstract references point to specific implementation classes
Student student=wqq;
Student.study ();
Worker worker=new wqq ();
Worker.work ();
Friend friend =new Wqq ();
Friend.play ();
}
}
An object that implements multiple interfaces and has multiple roles
Class Wqq implements Student,worker,friend {
@Override
public void Study () {
System.out.println ("learning");
}
@Override
public void work () {
System.out.println ("work");
}
@Override
public void Play () {
System.out.println ("Play Together");
}
}
Student role
Interface student{
void study ();
}
Staff role
Interface worker{
void work ();
}
Friend role
Interface friend{
void Play ();
}
Java Polymorphism (i)