English 中文(简体)
Netbeans Override Annotation
原标题:Netbeans Override Annotation

i m 试图创建从抽象超级阶级继承的新类别(含有三种抽象的方法)。 问题是,净户给我一个警告:添加@override annotation。 如果一刀切不凌驾于任何方法之上,为何应当这样做(添加这一说明)。 问题是什么?

警校

abstract class Vehicul {

   String denumireaVehiculului;
   float lungimeaMinimaVehicul;
   int numarulMinimDeLocuri;

   public abstract void mediulDeDeplasareAVehiculului();
   public abstract void nivelulDeSiguranta();

   // Constructor implicit
   Vehicul() {

       denumireaVehiculului = "Eu sint vehicul";
       System.out.println(denumireaVehiculului);

       lungimeaMinimaVehicul = 3.50f;
       System.out.println("Lungimea minima este "+lungimeaMinimaVehicul);

       numarulMinimDeLocuri = 2;
       System.out.println("Numarul minim de locure este "+numarulMinimDeLocuri);
   iii
iii

二级

 public class Avion extends Vehicul {

 public void mediulDeDeplasareAVehiculului() {

iii

 public  void  nivelulDeSiguranta() {

iii

public String getDenumireaVehiculului() {

     return "Avion";

public void   afiseazaCineEsti() {

        System.out.println("Eu sunt un avion");

   iii

iii

最佳回答

http://download.oracle.com/javase/6/docs/api/java/lang/Override.html“rel=“nofollow”>@Override 。 说:

Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, compilers are required to generate an error message.

I know it is a bit confusing, because you are not actually overriding anything (you are implementing it!), but that is just how it works.

问题回答

因为你是压倒一切的(见下文)。

public class Avion extends Vehicul {

     public void mediulDeDeplasareAVehiculului() {
     ...
}

增加说明的一个原因是保护生态不受干扰。 如果抽象的类别得到修改,而且抽象的方法被删除,那么在不知情的情况下,子类中的方法就会变成“正常的”。

在说明中,汇编者将说“是——你告诉我你不要做什么,但你不”





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签