Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I can't understand some statements in review questions of chapter 5 clearly (Java OCA 8)

 
Mushfiq Mammadov
Ranch Hand
Posts: 187
25
Java jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I can't understand the following statements clearly maybe for my poor English. Can you give any example codes about it? Thanks in advance.

On page 293, question #7, option E


On page 296, question #15, option C


On page 348, explanation option G of question 10

 
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
As you requested, I'll try to give a code snippet for every option/statement you didn't understand. Sometimes it will be hard, because all of them are incorrect statements

Mushfiq Mammadov wrote:On page 293, question #7, option E

According to this statement, with polymorphism you can create a public instance method in the superclass and it's guaranteed that this method (the one in the superclass) will be executed at runtime.
And the code to invoke the doIt method polymorphicallyNow (according to the statement of option E) we defined Super.doIt() as a public method, thus we are guaranteed that this code will print super (= the code invokes the superclass method at runtime). But we all know, this is complete nonsense. When a public method is overridden by a subclass, the subclass method will be executed at runtime (because that's what polymorphism is all about).
You could print super with this code, but then there would be no polymorphism in play (and the question clearly mentions these statements are all about polymorphims)

Mushfiq Mammadov wrote:On page 296, question #15, option C

This one is much easier than the previous one. And is easy to illustrate with a code exampleAccording to option C the concrete subclass must implement all methods defined in an inherited interface. So applied to the code snippet: does the Concrete subclass have to implement all methods defined in interface I (which is inherited through class Abstract)? Because the above code snippet compiles successfully, the answer is clearly no and option C is an incorrect statement. As the explanation in the study guide also states: some (or even all) of the methods could already be implemented by one of the superclasses. A concrete subclass must implement all abstract methods which are not yet implemented by one of its superclasses.

Mushfiq Mammadov wrote:On page 348, explanation option G of question 10

And this one is the most easy one of all According to option G this code compiles successfullyNo problem with line1, because we all know class java.lang.Object is the mother class of all classes. So every non-null instance (of any class) IS-A Object. But line2 does not compile, because interfaces can only extend other interfaces, it can't inherit from classes.
As you know, a class can only inherit from 1 class (multiple class inheritance is not allowed in Java). A class can implement 0, 1 or more interfaces in Java. So assume line2 would compile, I could write code likeAnd MyClass would have 2 parent classes: C3 (directly) and C1 (indirectly, through implementing interface I1). So that would be multiple class inheritance, which isn't supported by Java. That's why interfaces can only extend from other interfaces and not from classes. And thus option G is incorrect.

Hope it helps!
Kind regards,
Roel
 
Mushfiq Mammadov
Ranch Hand
Posts: 187
25
Java jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:As you requested, I'll try to give a code snippet for every option/statement you didn't understand.

Everything was clear when I saw examples without reading explanation) Really they are easy but sometimes it is a bit harder to understand statement for me without code snippet. Thank you for taking time to respond my question in detail! I find your post in each question in OCA forum, your explanations are great. Thanks a lot again
 
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
Mushfiq Mammadov wrote:Everything was clear when I saw examples without reading explanation) Really they are easy but sometimes it is a bit harder to understand statement for me without code snippet.

Although on the actual exam most questions will have a code snippet, there will be a few which are just plain text (like the ones you mentioned here). These could indeed be a little harder when you are not a native English speaker. But on the positive side: you always know how many answer you have to select for each question, so that might help a (whole) lot to answer a question correctly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic