1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

@overrideアノテーションについて

Posted at

アノテーションの種類

@override

  • overrideをつけると「必ずオーバーライドしてください」と指定することが可能
  • スペルミスなどが抑制できる

public class Test extends TestOverride {
 
           @Override
           public void outputs() {
                            System.out.println(“Hello World!”);
           }
 
           public static void main(String[] args) {
                      TestOverride cl = new TestOverride();
                      cl.output();
           }
}
 
public class TestOverride {
 
           public void output() {}
}
Documents $ 1java test.java
test.java:3: エラー:メソッドはスーパータイプのメソッドをオーバーライドまたは実装しません
           @override
           ^
エラー1個
エラー:コンパイルが失敗しました
Documents $ 1

参考にした記事

初心者向け】Javaのアノテーションの使い方を解説!代表例から自作方法まで
https://www.tech-teacher.jp/blog/java-annotation/#:~:text=%E3%81%AE%E3%81%8A%E5%95%8F%E3%81%84%E5%90%88%E3%82%8F%E3%81%9B-,%E3%82%A2%E3%83%8E%E3%83%86%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%A8%E3%81%AF,%E3%81%AA%E3%81%93%E3%81%A8%E3%81%8C%E8%A1%8C%E3%81%88%E3%81%BE%E3%81%99%E3%80%82

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?