簡體   English   中英

對於簡單的Java程序,在Eclipse中沒有輸出

[英]No output In Eclipse for a simple java program

我想我已經很好地編寫了該程序。 它沒有給我任何錯誤,但是也沒有給我任何輸出。 這有什么問題? 我檢查了其他程序,以查看Eclipse是否有任何問題,但是除此以外,其他所有程序都在運行。

注意:我是Java的新手。 詳細說明問題。 我知道我把繼承的拼寫寫錯了。

 public class Inheritence {
    int a;
    String b;

    Inheritence(int x, String y) {
        a = x;
        b = y;
    }
}

class B extends Inheritence {
    int c;

    B(int j, String k, int l) {
        super(4, "Srimanth");
        a = j;
        k = b;
        c = l;
    }

    public static void main(String args[]) {
        Inheritence obj1 = new Inheritence(4, "Srimanth");
        B obj2 = new B(4, "Srimanth", 5);

        System.out
                .println("The details of the guy are" + obj1.a + " " + obj1.b);
        System.out.println("The details of the guy are" + obj2.c);
    }

}

代碼中的錯誤是main方法是在非公共類B定義的。 將main方法移至公共類Inheritence或定義Inheritence的make類B子類,並定義具有main方法的Inheritance。

該文件的名稱是Inheritence.java?

在這種情況下,您應該將不同的類放在不同的文件中,然后調用具有main方法的類(最好編寫諸如“ String [] args”之類的參數)可能找不到main方法

當我運行它時,我得到以下信息:

error: Class names, 'Inheritence', are only accepted if annotation processing is
explicitly requested
1 error

嘗試更改文件名/類名。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM