• 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

test question

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been given a test question as below, I think the answer is 5), but not sure about this. Can somebody shed some light on this?
Thx
Pat
===============================================================
public class Foo
{
public void doIt( Field myField )
{
???
}
}
Given the above code, what code do you add to the doIt() method to find out whether myField is static?
Choice 1
if ( myField.isStatic() )
Choice 2
if ( myField.getModifier().isStatic() )
Choice 3
if ( Modifier.isStatic( myField.getModifiers() ) )
Choice 4
if ( myField.getModifiers() == Field.STATIC )
Choice 5
A Field object CANNOT represent a static field.
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only Choice 3 is correst. Go to java.lang.reflect package of javadoc to find out why.
http://java.sun.com/j2se/1.3/docs/api/index.html
To tell you the truth, I did not know the answer. I just went there and found out the answer. I believe you can do the same.
Thank you for asking this one.
Roseanne
Visit JavaChina on the web

 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW, Choice 5 is definite wrong. Just copied from the same place.

A Field provides information about, and dynamic access to, a single field of a class or an interface. The reflected field may be a class (static) field or an instance field.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic