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

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

Moderator: admin

Post Reply
suresh
Posts: 1
Joined: Mon Jun 08, 2015 11:05 am
Contact:

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

Post by suresh »

Not able to understand,1)String String,2)Integer Integer are valid declarations whereas int int is not.
Could you pl. explain?.

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

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

Post by admin »

int is a keyword, therefore it cannot be a name of a variable. You should try putting it in code and observe the error message.

realzakaria
Posts: 1
Joined: Wed Feb 17, 2016 10:21 am
Contact:

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

Post by realzakaria »

String and Integer are keywords too????? (confused!)

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

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

Post by admin »

realzakaria wrote:String and Integer are keywords too????? (confused!)
No, they are not. Here is a list of keywords:
https://docs.oracle.com/javase/tutorial ... words.html

nikitos
Posts: 21
Joined: Mon Oct 24, 2016 6:55 am
Contact:

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

Post by nikitos »

It's like member(local variable) shadowing?)

I mean that it's possible to shadow field of the class:

Code: Select all

class A{
int i=1;
void method(){
//shadowing here:
int i=2;
}
}

So I think it does not correlate with my meaning.
And user can have every name that is not from the "Java Building Block" (abstract, assert, boolean, etc)/
Last edited by nikitos on Thu Nov 10, 2016 5:51 am, edited 1 time in total.

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

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

Post by admin »

Sorry, I am not sure I understand your question. What is like member(local variable) shadowing?
Paul.

jax502
Posts: 2
Joined: Mon Nov 14, 2016 3:33 pm
Contact:

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

Post by jax502 »

Great question! This one got me. Yes String String is indeed a valid syntax. Probably not good coding practice but definitely valid. I need to watch out for these types of questions in the exam.

mj.anjuthan
Posts: 10
Joined: Thu Nov 10, 2016 3:07 am
Contact:

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

Post by mj.anjuthan »

Is there any possibility for an ambiguity (for compiler) while using a variable name same as a class name (say using "String")? (I'm not able to think of any.)

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

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

Post by admin »

No, there is no ambiguity.

Jose Manuel
Posts: 1
Joined: Wed Jan 25, 2017 4:13 pm
Contact:

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

Post by Jose Manuel »

I've been playing with the idea of using the same name for a class and for an instance of the class as follows:

class Person{

static void staticMethod(){}
void instanceMethod(){}

public static main void(String[] args){

Person Person = new Person(); //this compiles OK

//The problem comes here

Person.staticMethod(); // Ok, no problem at all
Person.instanceMethod(); // doesn't compile

}

I think Eclipse offers preference to the class before the instance.

¿Could anyone clarify it?

Thanks

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

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

Post by admin »

Could be a problem with Eclipse. Always use the command line and Oracle's Javac while practicing for the exam.

Deleted User 6318

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

Post by Deleted User 6318 »

JoseManuel, it compiles for me in IntelliJ (besides the fact that I needed to swap main and void - did it really compile for you like that)?

Deleted User 6318

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

Post by Deleted User 6318 »

I see beginIndex can be the same as endIndex - then the result is just empty. This is quite a paradox for me, because we include and exclude the same index at the same time.
I get how it work, but I think maybe it would be good to add this in the explanation, or make another question with such a case (if there isn't already one).

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

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

Post by admin »

Good point.
thanks for the feedback!

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests