• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

jqplus question.

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
This question is from jqplus.It goes like this:
Consider:
public class Outer
{
int i = 10;
class Inner
{
public void methodA()
{
//line 1.
}
}
}
Which of the following statements are valid at line 1 (Select the best answer).
1. System.out.println(this.i);
2. System.out.println(i);
3. System.out.println(Outer.this.i);
4. i cannot be accessed inside the inner class method.
Answer given is 3.
Isn't 2. also correct?How does one decide?
Thanks,
Rashmi.
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both 2 and 3 options are correct.
In real Exam, Questions (with choose the best answer) will not be asked.The Questions in real JCP are in very clear language and there is no ambiguity.
rajashree.
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Though both 2 and 3 are valid and produces results, the best answer will be 3..
Its is becoz, if we have say i=100; in the Inner class, then the Outer classe's 'i' is shadowed. So to properly access wheather 'i' is shadowed or not, Outer.this.i would be the best practice
Its my humble opinion
ragu
 
Ranch Hand
Posts: 1246
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree!!! 2 & 3.
Sometime the Mock is wrong.
And good luck on your exam
 
Enthuware Software Support
Posts: 4599
45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I searched for this question ( QID : 970934532250 ) and found that the explanation of this question clearly explains the answer and also notes that this is an ambigous question.
According to our database, a very similar question was asked in the exam.
This is what the explanation says:
-------------------------------
Actually option 2 is also correct but you are asked to select one option so you should select the best answer which is 3.
This sure is an ambigous question but we think that you should select option 3.
-------------------------------
------------------
SCJP2, SCWCD Resources, Free Question A Day, Mock Exam Results and More!
www.jdiscuss.com
Get Certified, Guaranteed!
JQPlus - For SCJP2
JWebPlus - For SCWCD
JDevPlus - For SCJD
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whether this question is an ambiguous one or not will depend on the kind of choice we are required to make. Remember, in the original exam we'll be told "select the one correct answer" and in that case, a radio button (not a check box) will be provided.
If so, then option 3 is correct.
In short, if you see a radio button, hit 3 ... if you see checkboxes, check 2 and 3
But of course, here...we see a "select the best choice" in the brackets...so 3 is correct.
Cheers
Shyam

[This message has been edited by Shyamsundar Gururaj (edited November 04, 2001).]
 
Rashmi Hosalli
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My sincere thanks to e'one.I think I know what I should be doing now!
Rashmi
 
Climb the rope! CLIMB THE ROPE! You too tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic