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

Question for Edward Finegan and Robert Liguori or anyone who has given OCAJP7

 
Rohan Deshmkh
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I earlier posted this question in one of the threads of certification results, but didn't got an answer as i posted it quite late after the discussion was over.
So i thought i would better ask it here.
I wanted to know if we get questions on garbage collection ,inner classess and object casting in the real OCAJP7 exam?
 
Robert James Liguori
Author
Ranch Hand
Posts: 551
5
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rohan Deshmkh wrote:I earlier posted this question in one of the threads of certification results, but didn't got an answer as i posted it quite late after the discussion was over.
So i thought i would better ask it here.
I wanted to know if we get questions on garbage collection ,inner classess and object casting in the real OCAJP7 exam?


Garbage Collection: No
Inner Classes: No
Casting: Yes, "Objective: Determine when casting is necessary"

Objectives (Refresh the page on the first visit):
http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=41&p_org_id=&lang=&p_exam_id=1Z0_803

-- Robert

 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3708
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rohan Deshmkh wrote:I earlier posted this question in one of the threads of certification results, but didn't got an answer as i posted it quite late after the discussion was over.
So i thought i would better ask it here.
I wanted to know if we get questions on garbage collection ,inner classess and object casting in the real OCAJP7 exam?


Although not mentioned explicitly in the exam objectives, some candidates have reported seeing questions on garbage collection in the OCAJP 7 exam. It is possible that they are unscored questions. That is why we have include a few very basic questions on this topic in our mock exam simulator.

HTH,
Paul.
 
Rohan Deshmkh
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Casting are the questions based on simple primitive type casting like :


or does it include object casting also.I often get confused in object casting.
For eg. see the following code:


I don't understand what does line B o2=(B)o1 will do? And which method from which class will be called using o2?
 
Tina Smith
Ranch Hand
Posts: 208
9
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have C IS-A B IS-A A, so it is legal to cast from a C instance to a B instance. You need the cast of course because you're casting down (since the compiler only knows it is an A) from A to B instead of up.

The line you describe
a) Declares a variable named o2 and specifies it holds something that is AT-LEAST a B. It might be something more specific (like a C) but will not be something less specific (like an A) or something random (like a String).
b) Converts the value in o1 to a B and stores the value in o2. A little explanation here: o1 IS-A C, but is stored in an A. The compiler knows that o1 is AT-LEAST an A, but could be something more specific like a B or a C (which it in fact is). You can't treat it like a C though because the compiler only knows you said it was an A.

o2 will call the method from the instance which it actually is. o2 IS-A C, because the object it was created from IS-A C. If you call m1() on both objects, you will find that they both refer to the C's implementation of the method. But the tricky part is if you ask for i on each object, you will find it refers to the object type it was declared as - o1 returns A's i and o2 returns B's i. This is because Java handles variable polymorphism differently than methods. Methods override and extend the functionality so you can call a method on a base class and it will execute the subclass's implementation. Variables will always return the instance they are located in. You cannot override a variable - redeclaring it in a subclass gives you two copies of the variable. When you reference the object as its subclass, you get the subclass variable, when you reference as the superclass, you get the superclass variable. This is called hiding.

Try compiling and running your example code then play with it a little - make sure that you call m1() from both instances, and read i from both instances to see what I mean.

The casting you need to be concerned with on the exam is object casting, and from what I remember of the beta the questions are similar to what you posted. You need to be able to determine if the code will compile, and if it compiles what the output will be. I found the OCJA to be pretty fair though. You need to know your stuff, but once you know it, they don't really go out of their way to trick you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic