This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what's ur answer to this question? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what Watch "what New topic
Author

what's ur answer to this question?

sath
Greenhorn

Joined: Aug 24, 2000
Posts: 5
Hi all,
I am a bit confused with the following question and all the more confused with the answer given - please help !!
Consider the following class...
class TestClass
{
int x;
public static void main(String[ ] args)
{
// lots of code.
}
}
Choose the correct answer:
a) By declaring x as static, main can access this.x
b) By declaring x as public, main can access this.x
c) By declaring x as protected, main can access this.x
d) Main can access This.x as it is declared now i.e. without any access modifier
e) By declaring x as private, main can access this.x
My answer was: a)
But answer given was d)
Howz this possible? Does anybody have any justification for this?
Thanks you very much
sath
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

IMO, thats' not possible.
Also a will not be correct either
since you don't have the this
variable for a static method.
Regds.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Paul A
Ranch Hand

Joined: Aug 25, 2000
Posts: 44
That sure is a tricky question...but I got it in my exam ( and that was about 8 months ago).
Though the wordings were a little bit different but the point was same. What the hell is 'This'!!!
Later on I came to know the answer (when we discussed among ourselves while creating our question bank). You have to assume that 'This' might be an object of class TestClass. If you assume this then the answer becomes very clear!
( Later on we found out that a few other people had also got same question)
HTH,
Paul. http://pages.about.com/jqplus

------------------
Get Certified, Guaranteed!


<A HREF="http://pages.about.com/jqplus" TARGET=_blank rel="nofollow">http://pages.about.com/jqplus</A> <BR>Get Certified, Guaranteed!
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
You have to assume that 'This' might be an object of class TestClass. If you assume this then....
I am sorry, but I refuse to make any assumptions
unless given in the qstn...and then who says
that I have to assume, well even if I why should
I assume that This is an obj of the
TestClass class.....yada yada yada........
Regds.
- satya
sath
Greenhorn

Joined: Aug 24, 2000
Posts: 5
I share the same opinion too.
Why should we make such an assumption in the first place?
So, if such a question appears in the exam what is to be done?
sath
Paul A
Ranch Hand

Joined: Aug 25, 2000
Posts: 44
Well, neither would I like to assume. But you know that you know concepts and you are taking the test to get the certificate. If you think that you won't get any vague/ambigous questions...you are in for a surprise buddy.
-Paul
 
Don't get me started about those stupid light bulbs.
 
subject: what's ur answer to this question?
 
Similar Threads
this from main method
Hierarch of non-static inner class
One more
kai's notes
confusing valid answer to a jq+ question