Page 1 of 2

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

Posted: Thu Feb 08, 2018 1:04 pm
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.

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

Posted: Fri Feb 09, 2018 4:09 pm
by ironicsushi
Thank you!

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

Posted: Tue Apr 17, 2018 7:12 am
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..

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

Posted: Tue Apr 17, 2018 8:47 am
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

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

Posted: Sun Feb 24, 2019 6:47 pm
by OlgaAG
the question removed as unnecessary

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

Posted: Sun Feb 24, 2019 7:33 pm
by admin
no, that is not truw. You can write a small program to check it out.