About Question enthuware.ocajp.i.v7.2.1092 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

admin
Site Admin
Posts: 10382
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1092 :

Post by admin »

No, null = null is an invalid statement. It will not even compile.
NullPointerException is thrown whenever you try to access an instance field or call an instance method using a reference that is pointing to null.

Angelica
Posts: 1
Joined: Fri Sep 11, 2020 4:49 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1092 :

Post by Angelica »

admin wrote:
Wed Aug 01, 2012 11:02 pm
The Holder class is actually a very basic (and well known) building block of a linked list. It is usually named "Node" and not Holder. Please google linked list to learn more.

Though not important for this exam, understanding how linked lists work is something that a programmer must know. You mentioned that you've been programming for years and I am surprised to know that you didn't recognize it.

HTH,
Paul.
I think having a mental picture of a linked list actually helps to understand and follow the code in this question even for someone who has not had to work with linked lists. Thank you for mentioning it!

Leonid
Posts: 9
Joined: Mon Jun 28, 2021 4:50 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1092 :

Post by Leonid »

a.link = b does not mean a.link = b.link. It means a.link points to the same object to which b is pointing.
I imagined a and b - these are some country, link and value there are some lakes. a has own lakes and b has own lakes. How lakes of a can be assigned to another country but not to another lake? How is a.link=b works in reality? When I have saw it my brain was broken. How it happened in programming area? Please give me to understand this.

vs2013
Posts: 9
Joined: Wed Jul 31, 2013 1:57 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1092 :

Post by vs2013 »

Hi,

What I don't understand is why this code even compiles when non-static variable 'link' is being accessed inside a static context:

Code: Select all

public static Holder setIt(final Holder x, final Holder y){
       x.link = y.link; //<-non-static variables?
       return x;
   }
Shouldn't this violate that rule? Thank you.

admin
Site Admin
Posts: 10382
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1092 :

Post by admin »

It is not being accessed from a static context. It is being accessed through variables x and y, which are pointing to instances of Holder class. The context of 'link' is the instance pointed to by x or y. If you try to access link without providing the context of an instance, then it would fail. Like this:

Code: Select all

public static void staticMethod(){
        System.out.println(link); //will not compile because here link is being accessed from a static context. static method does not have 'this'
}
public void instanceMethod(){
        System.out.println(link); //will compile because here link is being accessed through the implicit instance variable 'this'
}

Just a suggestion - You should go through a good book to understand the theory before attempting the questions. We recommend this: https://amzn.to/4dEACui

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 88 guests