This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Associate Certification (OCAJP 7) and the fly likes OCA Java SE 7 Programmer I Study guide - Master exam software Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Associate Certification (OCAJP 7)
Bookmark "OCA Java SE 7 Programmer I Study guide - Master exam software" Watch "OCA Java SE 7 Programmer I Study guide - Master exam software" New topic
Author

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

Devaney Marcondes
Greenhorn

Joined: Nov 22, 2012
Posts: 22
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
Bartender

Joined: Jul 19, 2004
Posts: 5126
    
  12

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.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Devaney Marcondes
Greenhorn

Joined: Nov 22, 2012
Posts: 22
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
Bartender

Joined: Jul 19, 2004
Posts: 5126
    
  12

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

Joined: Nov 22, 2012
Posts: 22
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
Bartender

Joined: Jul 19, 2004
Posts: 5126
    
  12

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

Joined: Nov 22, 2012
Posts: 22
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

Joined: Nov 22, 2012
Posts: 22
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
Bartender

Joined: Jul 19, 2004
Posts: 5126
    
  12

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

Joined: Nov 22, 2012
Posts: 22
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: OCA Java SE 7 Programmer I Study guide - Master exam software
 
Similar Threads
Updated: OCA 7 study materials
Java SE 7 OCA Certification Training Lab
OCA Java SE 7 Associate Study Guide (E&R Book) - printing
What other teaching materials would you recommend for OCA Java SE 7 Programmer I?
I Am OCAJP Certified for Java 7!!!