我試圖運行此代碼(在3個不同的類 - A,B和C),它沒有運行。我不知道爲什麼不。任何人都可以幫忙嗎?如何讓這段代碼運行?
public class A {
private int number;
protected String name;
public double price;
public A () {
System.out.println ("A() called"); }
private void foo1() {
System.out.println("A version of foo1() called"); }
protected int foo2(){
System.out.println("A version of foo2() called");
return number; }
public String foo3(){
System.out.println("A version of foo3() called");
return "Hi";
}
}
public class B extends A {
private char service;
public B () {
super();
System.out.println("B() called"); }
public void foo1 () {
System.out.println("B version of foo1() called"); }
protected int foo2 (){
int n = super.foo2();
System.out.println("B version of foo2() called");
return (n+5); }
public String foo3 () {
String temp = super.foo3 ();
System.out.println("B version of foo3()");
return (temp + " foo3"); } }
public class C extends B {
public C(){
super();
System.out.println("C() called"); }
public void foo1 () {
System.out.println("C version of foo1() called");
}
}
什麼,當你嘗試運行它發生?什麼是你看到的確切的異常或錯誤? – 2013-03-18 00:37:07
顯示你的錯誤! – Kickaha 2013-03-18 00:38:11
什麼,確切地說,你的意思是「它沒有運行」?它是否編譯?你期望它做什麼,它究竟做了什麼?程序是否啓動,但做錯了事,或者你不能啓動它? – 2013-03-18 00:38:17