File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what's ur answer to this question?

 
sath
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Paul A
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic