• Post Reply Bookmark Topic Watch Topic
  • New Topic

Overriding and static modifier - possible SYBEX OCP error  RSS feed

 
Ioanna Katsanou
Ranch Hand
Posts: 131
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone !!

I just started studying for the OCP exam, and I am reading
OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (Sybex)
I remember from the OCA exam that if the parent class has a non-static method, and the child class tried to override this with the static added then a compile error is generated.
For example:






Review Question 19 in Sybex Chapter 1,
says the following:

Which of the following can be inserted to override the superclass method? (Choose all that
apply.)


And for option D it has this answer:
D compiles but is not an override because it is
static.


I implemented the exact same example as above in Eclipse, and I still get a compiler error. Why does SYBEX says as an answer that D compiles??
is it a book mistake?

Many thanks,
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like the book is mistaken. I get a compiler error that says "this static method cannot hide the instance method ..."
 
O Shea
Ranch Hand
Posts: 196
3
Java MySQL Database Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya definitely its a mistake/mis-print
 
Ioanna Katsanou
Ranch Hand
Posts: 131
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everyone !!
 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you searched the errata link for your book?
 
Ioanna Katsanou
Ranch Hand
Posts: 131
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Campbell ,

Yes I have,

I searched in this link:

https://www.selikoff.net/java-ocp-8-programmer-ii-study-guide/

But I did not find it there.
Ioanna
 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are absolutely sure that error hasn't been reported, please try again to compile the code, and then report it yourself.
 
Ioanna Katsanou
Ranch Hand
Posts: 131
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heyy Campbell sorry my bad I just searched by book page and found that it has been reported -before I was searching by Appendix A -
#19: The answer is correct. The reason why D is wrong is incorrect. It does not compile because a static method cannot hide an instance method


Thank you ! Will search the errata by book page in the future
 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing to apologise for; it was quite difficult to find that erratum.
 
SunnyKumar Singh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Method overriding in java[url=https://javatutorial95.blogspot.in/2017/03/java-method-overriding.html]Method Overriding in java basically used to achieve run-time polymorphism and we can provide a specific implementation of the method. when parent and child both have the same name method with same number of arguments and same data types is called method overriding in java.

static modifier - java static modifier is used to save memory because we can call static method with class name there is no need to create an object of an class.
 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SunnyKumar Singh wrote:. . . java static modifier is used to save memory because we can call static method with class name there is no need to create an object of an class.
That is quite incorrect. The use of the static keyword has nothing to do with memory consumption. There are sometimes design decisions leading one to mark something static, but that is unusual.

And welcome to the Ranch
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!