• Post Reply Bookmark Topic Watch Topic
  • New Topic

Overriding  RSS feed

 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the following code an example of overriding ?? Netbeans is giving a warning.






Exception: java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - Apple is not abstract and does not override abstract method display() in food.Fruit
at Apple.<clinit>(Apple.java:11)
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shubham Semwal wrote:
Exception: java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - Apple is not abstract and does not override abstract method display() in food.Fruit
at Apple.<clinit>(Apple.java:11)


First, please read this... http://www.coderanch.com/how-to/java/FixAllCompilerErrorsBeforeRunningTheApplication


Anyway, to answer your question. In order to override a method, that method must be visible to the subclass that will be overriding the method.

In this case, since the method in the super class has the default access modifier, it is not visible to classes outside of its package -- ie. the method is not visible to your subclass. And hence, it is not considered as overriding.

Henry
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks..
I got it
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!