当前位置: 代码迷 >> Java相关 >> 有何错误
  详细解决方案

有何错误

热度:276   发布时间:2007-07-26 01:15:08.0
有何错误


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()");

}

}
高手帮忙看看有什么错误实在检查不出来了

搜索更多相关的解决方案: 何错误  

----------------解决方案--------------------------------------------------------

没人知道吗?


----------------解决方案--------------------------------------------------------
以下是引用antiantixy在2007-7-26 1:15:08的发言:


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里面的引号就可以了..
你粗心了..呵呵
----------------解决方案--------------------------------------------------------

  相关解决方案