/** * abstract class name as formal parameter * @author Administrator * */ //Define a human abstract class abstract class Person{ public abstract void study(); } class PersonDemo{ public void method(Person p){//p; p = new Student(); Person p = new Student //多态 p.study(); } } //Define a concrete class to implement this abstract class class StudentQ extends Person{ @Override public void study() { // TODO Auto-generated method stub System.out.println("Study hard"); } } public class AbstractTest { public static void main(String[] args){ // Currently there is no way to use //Because the abstract class has no corresponding concrete class //Then, we should first define a concrete class //Requirement: I want to use the method method in PersonMdemo PersonDemo pd =new PersonDemo(); StudentQ s = new StudentQ(); pd.method(s); } }
Abstract class name as formal parameter
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325936231&siteId=291194637
Recommended
Ranking