abstract class Shape {
protected double length;
protected double width;
Shape(double num,double num1){
length=num;
width=num1;
}
abstract double area();
}
class Square extends Shape{
Square(double num,double num1){
super(num,num1);
}
double area(){
System.out.println("正方形的面积 为 : ");
return length*width;
}
}
class Triangle extends Shape{
Triangle(double num,double num1){
super(num,num1);
}
double area(){
System.out.println("三角形的 面积 为: ");
return (0.5*length*width);
}
public class CalculateArea{
protected CalculateArea(){}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
Shape fObj;
Square sqobj =new Square(10, 20);
Triangle trobj=new Triangle(12,8);
fObj=sqobj;
System.out.println("fObj.area()");
fObj=trobj;
System.out.println("fObj.area()");
}
}
高手帮忙看看有什么错误实在检查不出来了
----------------解决方案--------------------------------------------------------
没人知道吗?
----------------解决方案--------------------------------------------------------
abstract class Shape {
protected double length;
protected double width;
Shape(double num,double num1){
length=num;
width=num1;
}
abstract double area();
}
class Square extends Shape{
Square(double num,double num1){
super(num,num1);
}
double area(){
System.out.println("正方形的面积 为 : ");
return length*width;
}
}
class Triangle extends Shape{
Triangle(double num,double num1){
super(num,num1);
}
double area(){
System.out.println("三角形的 面积 为: ");
return (0.5*length*width);
}
}
public class CalculateArea{
protected CalculateArea(){}
//}
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
Shape fObj;
Square sqobj =new Square(10, 20);
Triangle trobj=new Triangle(12,8);
fObj=sqobj;
System.out.println("fObj.area()");
fObj=trobj;
System.out.println("fObj.area()");
}
}
高手帮忙看看有什么错误实在检查不出来了
//小错误
abstract class Shape {
protected double length;
protected double width;
Shape(double num,double num1){
length=num;
width=num1;
}
abstract double area();
}
class Square extends Shape{
Square(double num,double num1){
super(num,num1);
}
double area(){
System.out.println("正方形的面积 为 : ");
return length*width;
}
}
class Triangle extends Shape{
Triangle(double num,double num1){
super(num,num1);
}
double area(){
System.out.println("三角形的 面积 为: ");
return (0.5*length*width);
}
}
public class CalculateArea{
protected CalculateArea(){}
//}
public static void main(String[] args) {
Shape fObj;
Square sqobj =new Square(10, 20);
Triangle trobj=new Triangle(12,8);
fObj=sqobj;
System.out.println(fObj.area());
fObj=trobj;
System.out.println(fObj.area());
}
}
----------------解决方案--------------------------------------------------------
去掉println里面的引号就可以了..
你粗心了..呵呵
----------------解决方案--------------------------------------------------------