• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Overriding and static modifier - possible SYBEX OCP error

 
Ranch Hand
Posts: 172
1
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Marshal
Posts: 16590
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ..."
 
Ranch Hand
Posts: 207
3
Oracle MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya definitely its a mistake/mis-print
 
Ioanna Katsanou
Ranch Hand
Posts: 172
1
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you everyone !!
 
Marshal
Posts: 73970
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you searched the errata link for your book?
 
Ioanna Katsanou
Ranch Hand
Posts: 172
1
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 73970
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 172
1
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 73970
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing to apologise for; it was quite difficult to find that erratum.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 73970
332
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic