为什么在main函数中给子类赋值 运行结果仍然为在子类中给属性赋值的结果
package com.shape;
public class Rcerangle extends Shape {
public double higher = 5;
public double longer = 4;
@Override
public void primeter() {
// TODO Auto-generated method stub
double primeter = 2*(higher+longer);
System.out.println("该矩形的周长为:" + primeter);
}
@Override
public void acreage() {
// TODO Auto-generated method stub
double acreage = higher * longer;
System.out.println("该矩形的面积为:" + acreage);
}
}
package com.shape;
//import java.util.Scanner;;
public class Text {
public static void main(String[] args) {
// TODO Auto-generated method stub
Shape obj1 = new Rcerangle();
Rcerangle si = new Rcerangle();
//Scanner input = new Scanner(System.in);
//System.out.println(obj.longer=input.nextDouble());
//System.out.println(obj.higher=input.nextDouble());
si.longer = 7;
obj1.primeter();
obj1.acreage();
Shape obj2 = new Cirlce();
obj2.primeter();
obj2.acreage();
}
该矩形的周长为:18.0
该矩形的面积为:20.0
该圆形的周长为:25.12
该圆形的面积为:50.24