• 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

Java SE 11 Developer Practice Tests (2021) Possible Errata Chapter 3

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I was reading "Chapter 3: Java Object Oriented Approach", and I came across question 65.

The answer to that question is marked as D, but it seems that answer C could also be a correct one:

D: super() is used to call a constructor in the parent class, while super is used to reference a member of the parent class. //is marked true in the book
C: super() is used to call a constructor in the parent class, while this is used to reference a member of the parent class. //but this is also true

Regards.
 
Saloon Keeper
Posts: 1328
40
Eclipse IDE Postgres Database C++ Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yassir:

You are almost there, but not quite.

Pardon my JShell, but it is good to know how to check stuff quick in JShell too.

jshell> class Base {
  ...>     void vmeth() { System.out.println("Base Class Method");}
  ...> }
|  created class Base

jshell> class Derived extends Base {
  ...>     @Override void vmeth() { System.out.println("Derived Override of Base Class Method");}
  ...> }
|  created class Derived

jshell> class Derived extends Base {
  ...>     @Override void vmeth() { System.out.println("Derived Override of Base Class Method");}
  ...>    void vmeth2() { this.vmeth();}
  ...>     void vmeth3() { super.vmeth();}
  ...> }
|  replaced class Derived

jshell> Derived d = new Derived();
d ==> Derived@5b37e0d2

jshell> d.vmeth2();
Derived Override of Base Class Method

jshell> d.vmeth3();
Base Class Method


Do you see that vmeth3() will always call the base class method, but vmeth2() will call the derived class method if one exists?

If there IS no override of the base class method, then this.method() will indeed happen to call the inherited base class method, that is true, but in general in the face of overriding and polymorphism, you use super.method() to explicitly call the base one.

And, welcome to the Ranch!!
 
Yassir Khaldi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Jesse,

I see what you mean, I didn't take polymorphism into consideration when I answered that question, I should have.
Thank you for your time to explain it.

Best Regards,
 
Jesse Silverman
Saloon Keeper
Posts: 1328
40
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lastly, is this the Mock Exams book published by Sybex with the authors Jeanne and Scott or some other book?

The authors themselves come on here periodically, so it is important to signal to them that it is actually there book if you expect to see it added to an Errata page like this one:
https://www.selikoff.net/ocp11-2/

EDIT -- there are a lot of preparation books, but a few of the most popular ones actually use this forum as the main means to report errata to the authors, such as the one I showed in a link.

 
author & internet detective
Posts: 40747
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is our practice tests book. The errata page is at https://www.selikoff.net/ocp11-pt/

This item is not on there (since it isn't an errata.). Good explanation Jesse!
 
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