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.
About Question enthuware.ocajp.i.v7.2.1320 :
Moderator: admin
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1320 :
If you like our products and services, please help us by posting your review here.
-
- Posts: 2
- Joined: Thu Feb 08, 2018 11:47 am
- Contact:
-
- Posts: 1
- Joined: Tue Apr 17, 2018 7:07 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1320 :
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..
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..
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1320 :
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.
-
- Posts: 10
- Joined: Thu Jan 03, 2019 3:08 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1320 :
the question removed as unnecessary
Last edited by OlgaAG on Mon Mar 11, 2019 2:09 am, edited 1 time in total.
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1320 :
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.
Who is online
Users browsing this forum: No registered users and 165 guests