一、abstract[抽象的]
1. abstract可以修饰类:
2. asbtract可以修饰方法:
3. 抽象可以定义子类:
二、static[静态的]
1. 可以修饰属性:
2.
3. 可以修饰方法:
4. 可以代码块 :
三、final[最终的、最后的]
1. final可以修饰变量:
2. final可以修饰方法:
3. final可以修饰类:
附:练习
1.
package demo;
public class zuoye7c6{
public static void main(String args[]){
//The Third Demand
Car a = new Car();
Truck b = new Truck();
a.setBrand("奔驰");
a.setColor("白色");
a.setSeats(5);
b.setBrand("福田");
b.setColor("红色");
b.setLoad(6.5);
a.showCar(a.getBrand(),a.getColor(),a.getSeats());
b.showTruck(b.getBrand(),b.getColor(),b.getLoad());
}
}
//父类
class Vehicles{
//1.属性
private String brand;//商标
private String color;//颜色
//封装
public void setBrand(String brand){
this.brand = brand;
}
public String getBrand(){
return brand;
}
public void setColor(String color){
this.color = color;
}
public String getColor(){
return color;
}
//3.功能方法(成员方法)
public void run(){
System.out.println("车已经启动");
}//行驶功能
public void showInfo(String brand,String color){
this.brand = brand;
this.color = color;
System.out.print("商标:"+brand+",颜色:"+color);
}//显示信息
}
//子类1
//The First Demand
class Car extends Vehicles{
//1.属性
private int seats;//座位
//封装
public void setSeats(int seats){
this.seats = seats;
}
public int getSeats(){
return seats;
}
//3.功能方法(成员方法)
public void showCar(String brand,String color,int seats){
super.showInfo(brand,color);
this.seats = seats;
System.out.println(",座位:"+seats);
}
}
//子类2
//The Second Demand
class Truck extends Vehicles{
//1.属性
double load;//载重
//封装
public void setLoad(double load){
this.load = load;
}
public double getLoad(){
return load;
}
//3.功能方法(成员方法)
public void showTruck(String brand,String color,double load){
super.showInfo(brand,color);
this.load = load;
System.out.println(",载重:"+load+"吨");
}
}
至此第九章结束