• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what's ur answer to this question?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I knew I would regret that burrito. But this tiny ad has never caused regrets:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic