簡體   English   中英

在Java中,要使用“super”關鍵字,我是否必須導入目標類?

[英]In Java, to use the “super” keyword, do I have to import the target class?

在構造函數中,當我們使用super關鍵字時,我們是否必須導入super引用的類(當super不引用Object時)?

class A extends ... {
    A() {
        super(); // do we need to import the class super refers to?
    }
}

是的,因為它在extends子句中。

super()本身不需要導入,但要有意義,你需要一個超類。 當然,如果是來自java.lang ,則無需導入它

如果超類不在同一個包中,或者它在java.lang中,則需要導入超類。 如果基類不可用,則super()無論如何都不起作用。

暫無
暫無

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

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