1.the abstract class
package ForDel;
/**
* @version: v1.0.0
* @author: Showi
* @date: 2019年10月15日 下午9:32:06
* @Describe:
* 1.abstrct class
* [1]the access right:
* private protected default public
* [2]final key word:just like const in cpp
* final func cannot overriding
* final class cannot be extend
* final variable cannot be correct
* tips:(1)the finnal object is a reference type,can's change the address,
* but the content can be change object.name = "";
* (2)typically, static final int maxsize = 100;
* [3]
* 2.interface
* 3.Multithreaded programming
*/
public class abstract_Interface {
public static void main(String[] args) {
printBoard pb = new printBoard();
pb.printBackground();
}
}
abstract class printControl{
static final String PROGRAMNAME = "excise";//the const variables
static final int MAXSIZE = 1000;//(2)typically, static final int maxsize = 100;
abstract void printBaseInfo();//use a abstract to describe the function
abstract void printBackground();
}
class printBoard extends printControl{
@Override
void printBaseInfo() {
System.out.println("the realize of printBaseInfo");
}
@Override
void printBackground() {
// TODO Auto-generated method stub
System.out.println("the realize of printBackground");
}
}
2.interface
public class abstract_Interface {
public static void main(String[] args) {
printControl pc = new HumanInfoPrint();//use interface to instantiate a child class
pc.printBaseInfo();
}
}
interface printControl{//a abstract class
//but only contain global constant variables and abstract functions
static final int MAXSIZE = 1000;//global constant variables
static final String SEX = "Male";
abstract void printBaseInfo();//abstract functions
}
class HumanInfoPrint implements printControl{//here can implements 2 more interface
String name = "Showi";
@Override
public void printBaseInfo() {
System.out.println("this is "+name);
}
}
class RobotInfoPrint implements printControl{
String name = "QQ小冰";
@Override
public void printBaseInfo() {
// TODO Auto-generated method stub
System.out.println("this is "+ name);
}
}