Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OCA Java SE 7 Programmer I Study guide - Master exam software

 
Devaney Marcondes
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone.
I was doing the Master Exam (the software that you can download when you buy the book OCA Java SE 7 Programmer I Study guide) and I found this question:
Given

Which methods are correct? (Choose all that apply.)
Correct Answer:

A:


B:


References EXPLANATION:

Question Given:
References
A and B are correct. A is correct because an object can act as any interface it implements.
B is correct because an object can also act as any of its superclasses.
C and D are incorrect. C is incorrect because a class cannot act as one of its subclasses.
This is because the subclasses will likely have methods that are not implemented in its parent class.
D is incorrect because the use of packages has nothing to do with inheritance.

-------------
In my opinion the answer B is wrong also, because it doesn't compile.
What do you think?

Thanks
 
Roel De Nijs
Sheriff
Posts: 9780
101
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct

B is incorrect, because for a legal override (method implementation) the access modifier can not be less visible. And all interface methods are public, so any method implementation should have public access modifier as well.

As a side note: These explanations are very weird. It seems that they should belong to another question, because this question has nothing to do with inheritance, but (based on A & B) with (in)valid implementations of an interface.
 
Devaney Marcondes
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:
As a side note: These explanations are very weird. It seems that they should belong to another question, because this question has nothing to do with inheritance, but (based on A & B) with (in)valid implementations of an interface.

You are right. The software indicated me that I was wrong and the explaining was a little strange.
I found a nother strange question:

Question Java 7's Garbage-First (G1) garbage collector is planned as the long-term replacement of
which collector?
Correct Answer D: Concurrent Mark-Sweep (CMS) Collector


References EXPLANATION: D is correct. Java 7's Garbage-First (G1) garbage collector
is planned as the long-term replacement of the Concurrent Mark-Sweep (CMS) collector.
A, B, and C are incorrect. A is incorrect because the G1 collector is replacing the CMS Collector,
not the Serial Collector. B is incorrect because the G1 collector is replacing the

LearnKey, Inc. Copyright 2006, All Rights Reserved.Page 6
CMS Collector, not the Parallel Collector. C is incorrect because the G1 Collector is replacing the CMS Collector, not the Parallel Compacting Collector.
REFERENCES: See Finegan, Edward and Robert Liguori. "OCA Java SE 7 Programmer I Study Guide (Exam 1Z0-803)." New York, McGraw-Hill, 2012.
Chapter 5: Understanding Methods and Variable Scope
OBJECTIVE: Understand Variable Scope
----------------------------
The answer could be right, but I didn't find any reference about the CMS in this book.
If someone would find I will be grateful if show me where it is.

Thanks.
 
Roel De Nijs
Sheriff
Posts: 9780
101
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That question is also complete out-of-scope. You don't have to know which internal algorithm GC is using to perform its duties. Certainly not for the OCAJP 7 certification. That's definitely an advanced question!
 
Devaney Marcondes
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't want open another topic because the title is the same but the question is different.

Given this method signature:

public void logEvent(String eventDescription) {/*Method Body */}


Which method overloads it?

A -

B -

C -

D - All of above


Correct Answer D: All of the above
References EXPLANATION: D is correct. They are all valid ways to overload the given method.
A, B, and C are incorrect. Each of these is not true; therefore, D is the correct answer


#####################################################

In my opinion the answer C is correct and the explanation doesn't make sense.
Experts, what do you think?
 
Roel De Nijs
Sheriff
Posts: 9780
101
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Devaney Marcondes wrote:Experts, what do you think?

D is the correct answer, all methods are valid overloads of the given method.

Why do you think only C is a valid overload? What are the rules for a valid overload?
 
Devaney Marcondes
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:
Devaney Marcondes wrote:Experts, what do you think?

D is the correct answer, all methods are valid overloads of the given method.

Why do you think only C is a valid overload? What are the rules for a valid overload?


Because I was wrong.
I thought that to overload a method the overloading method should have the same return.
I did a mistake.

Sorry and thank you.
 
Devaney Marcondes
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what do you think about this question?

If a variable is cast to a invalid objec, what is the effect?

A- (I don't Remember)
B- (I don't Remember)
C - A compile error will occur.
D - A runtime exception will be thrown.

Explanation: D is correct. This will causee a runtime exception to be throw.
A, B and C are incottect. A and B are incorrect because there is no way to proceed once a
casting error encountered. C is incorret because the compiler is unable to determine this is an error until runtime.

In my opinion the answer C and D are right. Why?
Look that:








The MyClassTest won't be compiled.

 
Roel De Nijs
Sheriff
Posts: 9780
101
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you try to cast between different inheritance trees (like casting a String to an Integer or your example) you'll get a compiler error. If you perform a wrong casting in the same inheritance tree, you'll get a runtime exception (e.g. casting an object to a String)
 
Devaney Marcondes
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:If you try to cast between different inheritance trees (like casting a String to an Integer or your example) you'll get a compiler error. If you perform a wrong casting in the same inheritance tree, you'll get a runtime exception (e.g. casting an object to a String)

Yes. Thus C and D are correct.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic