因为你的shape没有method()方法。我这么写:
package shape;
class Circle extends Shape{
public void method(){
System.out.println("circle");
}
}
class Square extends Shape{
public void method(){
System.out.println("square");
}
}
class Triangle extends Shape{
public void method(){
System.out.println("triangle");
}
}
public class Shape{
public void method() {
System.out.println("Shape")
}
public static void main(String arg[]){
Shape c=new Circle();
Shape s=new Square();
Shape t=new Triangle(); c.method();
s.method();
t.method();
}
package shape;
class Circle extends Shape{
public void method(){
System.out.println("circle");
}
}
class Square extends Shape{
public void method(){
System.out.println("square");
}
}
class Triangle extends Shape{
public void method(){
System.out.println("triangle");
}
}
public class Shape{
public void method() {
System.out.println("Shape")
}
public static void main(String arg[]){
Shape c=new Circle();
Shape s=new Square();
Shape t=new Triangle(); c.method();
s.method();
t.method();
}
解决方案 »
- 关于null的问题
- 两个简单问题先来先给分[网络 + string]
- 想买个笔记本做程序开发!有路过的大虾推荐下性价比高的,不要提那些很贵的!6000以下的,谢了!
- ■一初级J2SE程序求稿,拟做PDA的备忘录,谢谢大家.■
- 请问使用SequenceInputStream顺序流类是否可以把2个或者多个InputStream连接起来当做一个流使用呢..如果可以请问如何实现
- 正则表达式的问题
- 高分求一个缩放程序源码
- 关于分页问题的讨论,想找一个比较折中的办法。
- 有关JBuilder5的几个问题,先解答者有分,谢谢!
- 如何控制子目录及文件的数量
- 有人说.net比java快39倍,我不信,有没有知道.net和java的区别的
- 网络文件下载该用哪个类呀?
public class Shape{
public void method() {
System.out.println("Shape");
}
你这里的Shape和Circle没有一点关系啊
当然会报错了~~~~~
是不是你的Circle有一个shape的接口阿还是circle就是直接继承了
Shape啊?
private int value;
private Note(int val) { value = val; }
public static final Note
middleC = new Note(0),
cSharp = new Note(1),
cFlat = new Note(2);
} // Etc.class Instrument {
public void play(Note n) {
System.out.println("Instrument.play()");
}
}// Wind objects are instruments
// because they have the same interface:
class Wind extends Instrument {
// Redefine interface method:
public void play(Note n) {
System.out.println("Wind.play()");
}
}public class Music {
public static void tune(Instrument i) {
// ...
i.play(Note.middleC);
}
public static void main(String[] args) {
Wind flute = new Wind();
tune(flute); // Upcasting
}
}