1. 程式人生 > >(JAVA基礎)JAVA中抽象函式的設定及書寫

(JAVA基礎)JAVA中抽象函式的設定及書寫

抽象函式就那麼多的概念,關鍵還是看實戰的應用,不多說,直接程式碼!

/**
 * @author Administrator
 *
 */
package stduy;

import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

abstract class Employee{
		private String name;
		private String id;
		private double sal;
		
		Employee(String name,String id,double sal) {
			// TODO Auto-generated constructor stub
			this.name = name;
			this.id = id;
			this.sal = sal;
		
		}
		
		public abstract void work();
		
}

class Programmer extends Employee{
	
	Programmer(String name,String id,double sal) {
		// TODO Auto-generated constructor stub
		super(name ,id ,sal);
	}
	public  void work() {
		System.out.println("coding");
	}
	
}

class Manager extends Employee{
	private double bonus;
	public Manager(String name, String id, double sal,double bonus) {
			// TODO Auto-generated constructor stub
			super(name, id, sal);
			this.bonus = bonus;
	}
	
	public void work() {
			
			System.out.println("Doing some manage thimgs");
	}
	
}


public class Main{
	
	public static void main(String[] args) {
			
			Manager manager = new Manager("TangYuan" , " 000001" ,  1000000 , 100000000);
			manager.work();
			
			Programmer programmer = new Programmer("WangJiang" , "000022", 100000);
			programmer.work();
		
	}
	
}