2016/04/12

Source: Internet
Author: User

Not all classes need to be abstract classes only use abstract classes when they are never used for downward transformation.

Interface:

interface Keyword Intterface

The first feature of the interface: the methods inside are all abstract methods

Interface The second feature: The properties inside are both static and final if you don't add the write modifier, the system will automatically add to you, generally not putting the attribute in the interface.

An interface is an ability to represent a power who realizes who he is.

Implementation of the interface: key character implements he put it behind the inherited keyword.

Interface and interface implementation is also the relationship of is a

Inheritance can only be single-inheritance, but interfaces can be multiple implementations as long as the middle uses commas to separate

Inheritance is an abstraction of an object's abstract interface, which is the behavior (capability)

Upward transformation: person p = new Man (); No forced type conversions are required for upward transformation
Down transformation: Man man = (man) new person (); Type conversions must be enforced

Package Com.wode.wok;
/**
*
* @author Administrator
* Establishment of an aircraft class
*/
Public class airplane implements fly{

@Override
public void Proceed () {
TODO auto-generated Method Stub
SYSTEM.OUT.PRINTLN ("aircraft will Fly");
}

}

Package Com.wode.wok;
/**
*
* @author Administrator
* Build a bird he can fly again
*/
public class Bird implements fly{

@Override
public void Proceed () {
TODO auto-generated Method Stub
System.out.println ("Bird will Fly");
}

}

Package Com.wode.wok;
/**
*
* @author Administrator
* Build a flying interface/that is the ability
*/
Public interface Fly {
/**
* Take off
*/
public void proceed ();

}

Package Com.wode.wok;
/**
*
* @author Administrator
* Build a Super ability
*/
Public interface Superability {

public void superability ();
}

Package Com.wode.wok;
/**
*
* @author Administrator
* Build a super human Superman can fly
*/
Public class Superman implements fly,superability{
public void Show () {
System.out.println ("I Am Superman");
}

@Override
public void Proceed () {
TODO auto-generated Method Stub
System.out.println ("Superman Will Fly");
}

@Override
public void superability () {
TODO auto-generated Method Stub
System.out.println ("Superman Can save the World");
}

}

Package Com.wode.wok;

Import Java.util.Scanner;

public class Test1 {

/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub

Scanner Scanner = new Scanner (system.in);
for (int i =5; i>=0;i--) {
System.out.println ("Please enter the thing you want to see 1: Airplane 2: Superman 3: Bird");
int look = Scanner.nextint ();
if (look==1) {
Airplane airplane = new airplane ();
Airplane.proceed ();
}
if (look==2) {
Superman Superman = new Superman ();
Superman.show ();
Superman.proceed ();
Superman.superability ();
}
if (look==3) {
Bird Bird = new Bird ();
Bird.proceed ();
}else if (look!=1&&look!=2&&look!=3) {
SYSTEM.OUT.PRINTLN ("Wrong input! ");
}
System.out.println ("You also have the opportunity to" +i+ ");
}

}

}

2016/04/12

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.