1.An abstract,sa its name suggest,is something abstract.But we still can realize methods in it.
2.An abstract method in abstract class can't be realized when defined,we can only realize it in its subclass
What is a template
The defination rom Internet:
完成一件事情,有固定的数个步骤,但是每个步骤根据对象的不同,而实现细节不同;
就可以子啊父类中定义一个完成该事情的总方法。每个步骤的具体实现,由子类完成。
Abstract class
Can't instantiate
There are conventional methods,but an abstract method can only be implemented in its subclass.
When we need a template,we should create an abstract class,and realize its functions in the subclass. -- Start -> pause->stop->exit
Using abstract class template to realize the method of building a house:
public abstract class Drawings{
public void buildHouse{
String type = getHouseType();
String color = getHouseColor();
String material = getHousematerial();
System.out.println("You will build a "+color+type" using "+material):
}
public abstract String getHousetype();
public abstract String getHouseColor();
publice abstract String getHouseMaterial();
}
public class Workers extends Drawings{
@Override
public abstract String getHousetype(){
return "Villa"
}
@Override
public abstract String getHouseColor(){
return "Colourful"
}
@Override
publice abstract String getHouseMaterial(){
return "Ferroconcrete"
}
}
public class MyClass{
Woker xw = new Woker();
xw.buildHouse();
}