• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static method "inheritance" an OCAJP7 exam topic?

 
Chris Barrett
Bartender
Posts: 317
24
Eclipse IDE Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

This is sort of a continuation of this thread - http://www.coderanch.com/t/638310/java/java/Static-methods-overridden
Since the OP's question was answered, and mine was more specific to the OCAJP7 exam content and Mala Gupta's book, I've posted here.

My understanding is that in addition to static methods, private and final methods are also compile time generated, as these cannot be overridden. Binding of overridden methods happen at runtime.

I have been studying using Mala Gupta's excellent OCAJP7 prep book. In Chapter 6.6.2 under Polymorphism, the book discusses instance variables inheritance - mentioning "With inheritance, the instance variables bind at compile time and the methods bind at runtime." and again as an Exam Tip: "Watch out for code in the exam that uses variables of the base class to refer to objects of the derived class and then accesses variables and methods of the referenced object. Remember that variables bind at compile time, whereas methods bind at runtime." In the section, I didn't see anything about attempting to override static methods.

Has anyone run into questions about static method inheritance in the OCA exam?

Perhaps the text should be updated to say "whereas overridden methods bind at runtime.", and provide an example of hiding static methods?

Cheers!
Chris



 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris R Barrett wrote:My understanding is that in addition to static methods, private and final methods are also compile time generated, as these cannot be overridden. Binding of overridden methods happen at runtime.

That's an important rule. If you know this very well, you can easily spot compiler errors on the exam (and you don't have to waste time to determine the output of a few nested loops). Luckily this rule is not hard at all. Which methods you can call/invoke is determined at compile time (using the reference variable type). Which method is actually executed is decided at runtime (based on the type of the actual object).

Chris R Barrett wrote:I have been studying using Mala Gupta's excellent OCAJP7 prep book. In Chapter 6.6.2 under Polymorphism, the book discusses instance variables inheritance - mentioning "With inheritance, the instance variables bind at compile time and the methods bind at runtime." and again as an Exam Tip: "Watch out for code in the exam that uses variables of the base class to refer to objects of the derived class and then accesses variables and methods of the referenced object. Remember that variables bind at compile time, whereas methods bind at runtime." In the section, I didn't see anything about attempting to override static methods.

The Mala Gupta book is a 1st edition and doesn't have editions for previous OCPJP exams. So it's a new kid on the block, a true first-timer. That means the text is read (and re-read) by just "a few" people and it's very, very, very hard to write sentences which are clear (unambiguous), obvious and correct. A book like K&B (which is an old kid on the block) has already several editions for previous OCPJP exams, so it's read (and re-read) by much more people. That increases the chance that ambiguous sentences are removed, rephrased or replaced.

Chris R Barrett wrote:Has anyone run into questions about static method inheritance in the OCA exam?

That really shouldn't matter If you know your stuff (and it seems you do), you'll be able to answer any question on this topic. But the exam objectives cover inheritance, static methods, overloading and overriding; so I think it's safe to say you might see a question with a hidden static method in it.

Chris R Barrett wrote:Perhaps the text should be updated to say "whereas overridden methods bind at runtime.", and provide an example of hiding static methods?

That's a good proposal. A concrete (appropriate) example is always an added value! But I'm not a huge fan of the used verb "bind". What does that actually mean? It appears to have 16 different meanings and even one from computing: "To associate an identifier with a value; to associate a variable name, method name, etc. with the content of a storage location.". So if I were the author, I would avoid the use of "bind". And I would stick to the rule I mentioned above. Maybe an additional note can be added to emphasize the fact that you can only override a method (and thus have polymorphic behavior), if the method is inherited. Methods which are private, final or static are not inherited, so don't qualify to be overridden.

Hope it helps!
Kind regards,
Roel

(I notified the author about this thread and your proposal to improve the book)
 
Chris Barrett
Bartender
Posts: 317
24
Eclipse IDE Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roel,

Thank you so much for the feedback!

Just to be clear, I didn't mean to imply I was knocking her book. I apologize if that's how you felt. It's an excellent book!
This wasn't even really an issue, more of a thought for the future. I used binding as the text already used it to describe instance variables.

You know, the only real "issue" I saw was this super minor grammar error in Chapter 1:


Thank you for the vote of confidence - I'll know in a few weeks.

Cheers!
Chris
 
Mala Gupta
Author
Ranch Hand
Posts: 363
11
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris-
Thanks for posting your concern and the typo :-). Point taken.

I'm pleased to learn that you are enjoying reading this book. I wish you Good Luck and hope you pass the exam with flying colors.

Hi Roel-
Thanks for the notification and your inputs. Much appreciated.

With much respect,
Mala
 
Chris Barrett
Bartender
Posts: 317
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both for the feedback.

I've marked as resolved in order to move it out of the "queue".

Cheers!
Chris
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris R Barrett wrote:Just to be clear, I didn't mean to imply I was knocking her book. I apologize if that's how you felt. It's an excellent book!

No need to apologize. That thought had not occurred to me. I just wanted to give some background information about the book. I also think it's a very good book, otherwise I wouldn't recommend it here on the ranch (my quote would not be on the back cover of the book )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic