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

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: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

It is true that static variables belong to the class. But that has nothing to do this.
a is reference of type ABCD. Yes, a refers to an object of type MNOP, but the declared type of a is ABCD and the compiler only checks the declared type of the reference variable to determine which variable it needs to use.

Compiler does not know the type of the actual object that will be referred to by a variable. Only a JVM can know that. In case of instance methods, the compiler defers this decision to the JVM and that is why methods are polymorphic. In case of variables and static methods, the compiler makes the decision by itself just by looking at the type of the variable.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

ironicsushi
Posts: 2
Joined: Thu Feb 08, 2018 11:47 am
Contact:

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

Post by ironicsushi »

Thank you!

cknoxo
Posts: 1
Joined: Tue Apr 17, 2018 7:07 am
Contact:

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

Post by cknoxo »

I take it when they show these classes together, they aren't to be thought of as compiled in the same .java class?
Because this would throw a compile error..
Kind of sneaky unless it says somewhere that "anytime a question shows multiple classes in the one code print, consider it as a different .java file for each class"
If you put all the code shown into one .java file it wont like the int x in MNOP as its the same name as the one in ABCD. If you made the x in ABCD private, it would fix the issue. So i put compilation error and got it wrong..

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

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

Post by admin »

Yes, Oracle has mentioned this on their official 1z0-808 certification details page:
No file or directory path names for classes: If a question does not state the file names or directory locations of classes, then assume one of the following, whichever will enable the code to compile and run:
All classes are in one file
Each class is contained in a separate file, and all files are in one directory
If you like our products and services, please help us by posting your review here.

OlgaAG
Posts: 10
Joined: Thu Jan 03, 2019 3:08 pm
Contact:

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

Post by OlgaAG »

the question removed as unnecessary
Last edited by OlgaAG on Mon Mar 11, 2019 2:09 am, edited 1 time in total.

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

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

Post by admin »

no, that is not truw. You can write a small program to check it out.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 40 guests