Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General 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 ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Dan Chisholm Chapter 4, question 15

 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

My answer: a, b, d, e

Dan's answers don't agree with mine.
Someone wanna set me straight on the semantics?
[ February 09, 2003: Message edited by: Garrett Smith ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The method run() here is not static.
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getRunnable() is static.
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Garrett Smith:
getRunnable() is static.


Garrett,
You have declared an anonymous class inside of a static method. Although the text used to declare the anonymous class appears "inside" of a static method, the anonymous class itself is not static. An instance of the anonymous class exists and instance methods within the anonymous class are able to refer to that instance using the "this" reference.
For the purposes of the SCJP exam, a statement such as

The keyword "this" can not be used inside the body of a static method.

refers to the immediately enclosing method. The question does not refer to an instance method within an instance of an inner class declared within the body of a static method.
I hope that helps.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But the this and the super have nothing to do with getRunnable(). Their context is the instance of the anonymous subclass of Runnable.
And you are using them in a nonstatic method, that is run().
Sort of...
-Barry
Sorry Dan didn't see your post down there...
[ February 10, 2003: Message edited by: Barry Gaunt ]
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic