Java, the keyword abstract (abstract classes and abstract methods)


/ *
* Abstract using keywords
* 1.abstract: abstract
* 2.abstract can be used to modify the structure: Class, Method
*
* 3. Modified abstract class: abstract
*> such can not be instantiated
*> abstract class there must be a constructor, to facilitate call when the subclass is instantiated (involving: subclass object instantiated whole process)
*> development, are provided subclasses of the abstract class so that the child class object is instantiated, are supposed to do
*
*
* 4. abstract modification methods: method abstract
*> the only way to abstract method declarations, no method body
*> contains the abstract class methods, it must be an abstract class. Conversely, there may be no abstract class abstract methods.
*> If a subclass overrides After all the abstract methods of the parent class, the subclass is instantiated only
* if not all of the subclasses of the abstract parent class for reprogramming This abstract class is a subclass, abstract modification required
* /
public class AbstractTest {
public static void main (String [] args) {

// Once the abstract Person class, it can not be instantiated
// new new Person Person P1 = ();
// p1.eat () ;

}
}

abstract class Creature{
public abstract void breath();
}

abstract class Person extends Creature{
String name;
int age;

public Person(){

}
public Person(String name,int age){
this.name = name;
this.age = age;
}

//不是抽象方法:
// public void eat(){
//
// }
//抽象方法
public abstract void eat();

public void walk(){
System.out.println("人走路");
}


}


class Student extends Person{

public Student(String name,int age){
super(name,age);
}
public Student(){
}

EAT void public () {
System.out.println ( "Student more nutritious foods");
}

@Override
public void Breath () {
System.out.println ( "student should not haze of the fresh air" );
}
}

Guess you like

Origin www.cnblogs.com/wpy188/p/12081675.html