java abstract class and interface

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);
		
	}
	
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值