• Post Reply Bookmark Topic Watch Topic
  • New Topic

overriding method  RSS feed

 
fahmida tasnim prema
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we override a method and make it private ?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Have you tried it? It just takes a minute...

Henry
 
salvin francis
Bartender
Posts: 1664
37
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to coderanch
 
fahmida tasnim prema
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i checked it ..it shows some error .........saying that i have to make it public .........but netbeans allowing me to run the code anyway and also giving me the output. if its a compilation error why netbeans is showing me output
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fahmida tasnim prema wrote:if its a compilation error why netbeans is showing me output


Netbeans, along with the majority of IDEs, allow the running of code that doesn't compile. This is mostly done for testing purposes -- as you can have a ridiculous amount of code that you haven't completed yet, and want to test a component.

This is clearly *not* in the Java specifications, and if you chose to use that option, you are on your own. The behavior, and hence, the answer to "why?", is not defined.

Henry

 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The idea behind overriding is that the overriding method is a specialised form of the overridden method. So, whenever the user calls the overridden method, they expect it to work.You cannot therefore make the eat method less accessible in Cat than in Animal. If it is public in Animal, then users will expect to be able to call in it any kind of Animal, so they will expect it to be public there, too.

The IDE flags a syntax error and attempts to compile the code when you click run. During the compilation process it detects an error message and the code then fails to run any further. It may be that some code has been compiled and executed before the compiler error becomes obvious; as Henry says, don't try to run code with such errors. This behaviour may vary from IDE to IDE and is not defined.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!