About Question enthuware.ocajp.i.v7.2.1022 :
Moderator: admin
-
- Posts: 1
- Joined: Mon Jun 08, 2015 11:05 am
- Contact:
About Question enthuware.ocajp.i.v7.2.1022 :
Not able to understand,1)String String,2)Integer Integer are valid declarations whereas int int is not.
Could you pl. explain?.
Could you pl. explain?.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1022 :
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.
-
- Posts: 1
- Joined: Wed Feb 17, 2016 10:21 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1022 :
String and Integer are keywords too????? (confused!)
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1022 :
No, they are not. Here is a list of keywords:realzakaria wrote:String and Integer are keywords too????? (confused!)
https://docs.oracle.com/javase/tutorial ... words.html
-
- Posts: 21
- Joined: Mon Oct 24, 2016 6:55 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1022 :
It's like member(local variable) shadowing?)
I mean that it's possible to shadow field of the class:
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)/
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.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1022 :
Sorry, I am not sure I understand your question. What is like member(local variable) shadowing?
Paul.
Paul.
-
- Posts: 2
- Joined: Mon Nov 14, 2016 3:33 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1022 :
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.
-
- Posts: 10
- Joined: Thu Nov 10, 2016 3:07 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1022 :
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.)
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1022 :
No, there is no ambiguity.
-
- Posts: 1
- Joined: Wed Jan 25, 2017 4:13 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1022 :
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
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
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1022 :
Could be a problem with Eclipse. Always use the command line and Oracle's Javac while practicing for the exam.
Re: About Question enthuware.ocajp.i.v7.2.1022 :
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)?
Re: About Question enthuware.ocajp.i.v7.2.1022 :
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).
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).
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1022 :
Good point.
thanks for the feedback!
thanks for the feedback!
Who is online
Users browsing this forum: No registered users and 13 guests