Trending News
Promoted
我寫的計算面積怪怪的(用到interface)
interface basic
{
final int length = 10;
public abstract int show();
}
class square implements basic
{
public int show()
{
System.out.println("square");
return length * length;
}
}
class cube implements baisc
{
public int show()
{
System.out.println("cube");
return length * length * 6;
}
}
public class test
{
public static void main(String args[])
{
basic a;
a = new square();
System.out.println(a.show());
a = new cube();
System.out.println(a.show());
}
}
Still have questions? Get your answers by asking now.