abstract class shape
{
public abstract void square();
}
class shape1 extends shape{
float bianchang=3.14;
public void square()
{
System.out.println( bianchang*bianchang);
}}
class shape2 extends shape{
float bianchang=3.14;
float kuangdu=9.6;
public void square()
{
System.out.println( bianchang*kuangdu*bianchang);
}}
public class Test
{
public static void main(String[] args)
{
shape A=new shape1;
shape B=new shape2;
square(shape A);
square(shape B); }
}
我想学java 可是为什么 不能够编译成功
{
public abstract void square();
}
class shape1 extends shape{
float bianchang=3.14;
public void square()
{
System.out.println( bianchang*bianchang);
}}
class shape2 extends shape{
float bianchang=3.14;
float kuangdu=9.6;
public void square()
{
System.out.println( bianchang*kuangdu*bianchang);
}}
public class Test
{
public static void main(String[] args)
{
shape A=new shape1;
shape B=new shape2;
square(shape A);
square(shape B); }
}
我想学java 可是为什么 不能够编译成功
abstract class shape
{
public abstract void square();
}
class shape1 extends shape{
float bianchang=3.14f;
public void square()
{
System.out.println( bianchang*bianchang);
}}
class shape2 extends shape{
float bianchang=3.14f;
float kuangdu=9.6f;
public void square()
{
System.out.println( bianchang*kuangdu*bianchang);
}
}public class Test
{
public static void main(String[] args)
{
shape A=new shape1();
shape B=new shape2();
A.square();
B.square();
}
}
3.14默认是double类型的,要是标志是float要在后面加上f 或 F
shape A=new shape1();
shape B=new shape2();
A.square();
B.square();
另外