Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Marcus Green Exam #3, Question 40

Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Original Question:
Given the following code
class Base{
static int oak=99;
public class Doverdale extends Base{
public static void main(String argv[]){
Doverdale d = new Doverdale();
public void amethod(){
Which of the following if placed after the comment //Here, will compile and modify the value of the variable oak?
1) super.oak=1;
2) oak=33;
3) Base.oak=22;
4) oak=50.1;
The answers given is 1, 2, 3
I have to contend again here (sorry Marcus :-) that answer
1 is not correct, since in a static context, there is not
such thing as "super" or "this". So answer 1 is incorrect.
The correct answer is 2, 3.
Would anyone please comment? Thanks! Sam
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marcus is correct. Look at the code, you are not calling super in a static method, so super does have a meaning in this case. super and this can be made in non-static methods as they relate to the current object, and non-static methods can only be called when you have created an object.
You can still call static methods or static variables of the base class from non-static methods using super and this and maybe that is where you got confused.
[This message has been edited by bill bozeman (edited December 18, 2000).]
Do not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic