2014-07-16 14 views
-4
class Base1 { 
    int x=50; 
} 

class Child extends Base1{ 
    int x=20; 
    void show() { 
     System.out.println(x); 
    } 

    public static void main(String[] args) { 
     Child c1=new Child(); 
     c1.show(); 
    } 
} 

您好我是新來的Java編程和試圖在Netbeans中運行上面的代碼中,我得到了一個錯誤傳承試圖使程序

Error: Main method not found in class base1.Base1, please define the main method as:
public static void main(String[] args)

請給予解決

+3

「_please give the solution_」請學習Java。 – Unihedron

+0

請轉到[The Java Tutorials:** Learning the Java Language **](http://docs.oracle.com/javase/tutorial/java/index.html) – Barranka

回答

2

類與main方法需要是public

public class Child extends Base1 
+1

您應該只有一個'public'類該文件應該與其包含的文件具有相同的名稱。 – hakcho

1

你不能在1個classfile中有多個類,如果這些是內部類,那麼你需要把public static void main(...)放在外部類中。