1. 程式人生 > >【Java-8】繼承

【Java-8】繼承

父與子

package bao1;

public class Student {
	String name="abc"; // 定義一個成員變數name
	private void SetName(String name) { // 定義一個引數(區域性變數)name
		this.name = name; // 將區域性變數的值傳遞給成員變數
	}
}

class small_Student extends Student{
	int tag;
	public void func(){
		System.out.println("小學生!");	
	}
	
}

class big_Student extends Student{
	int tag;
	public void func(){
		System.out.println("大學生!");	
	}
}

////
package bao1;

public class wsdx{
	public static void main(String[] arg){
		small_Student Student1=new small_Student();
		System.out.println(Student1.name);
		
	}
}