面向对象三大特性 封装 继承 多态
抽象类: 包含一个或者多个抽象方法的类;
接口:方法全部为冲向方法,其实也是抽象类:
继承:被继承的类叫父类.当父类抽象类的时候要实现抽象方法;
接口可以多(实现)继承,非接口只能单继承。
抽象类: 包含一个或者多个抽象方法的类;
接口:方法全部为冲向方法,其实也是抽象类:
继承:被继承的类叫父类.当父类抽象类的时候要实现抽象方法;
接口可以多(实现)继承,非接口只能单继承。
2017-05-27
静态方法是可以直接调用静态方法的,所以
public class HelloWorld {
static int score1 = 86;
static int score2 = 92;
public static int sum() {
return score1+score2;
}
public static void main(String[] args) {
int allScore = sum();
System.out.println("总分:" + allScore);
}
}
public class HelloWorld {
static int score1 = 86;
static int score2 = 92;
public static int sum() {
return score1+score2;
}
public static void main(String[] args) {
int allScore = sum();
System.out.println("总分:" + allScore);
}
}
2017-05-26
public static void main(String[] args) {
Shape s1=new Rectangle();
System.out.println("矩形的周长是:"+s1.calPerimeter());
System.out.println("矩形的面积是:"+s1.calArea());
Shape s2=new Circle();
System.out.println("圆的周长是:"+s2.calPerimeter());
System.out.println("圆的面积是:"+s2.calArea());
}
Shape s1=new Rectangle();
System.out.println("矩形的周长是:"+s1.calPerimeter());
System.out.println("矩形的面积是:"+s1.calArea());
Shape s2=new Circle();
System.out.println("圆的周长是:"+s2.calPerimeter());
System.out.println("圆的面积是:"+s2.calArea());
}
2017-05-26
/**
* 圆形
* @author Administrator
*
*/
public class Circle extends Shape {
public double calPerimeter() {
return 2*pi*radius;
}
public double calArea() {
return pi*radius*radius;
}
}
* 圆形
* @author Administrator
*
*/
public class Circle extends Shape {
public double calPerimeter() {
return 2*pi*radius;
}
public double calArea() {
return pi*radius*radius;
}
}
2017-05-26