Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

static imports

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

This question is from K&B - Chap 10 Self Tests ..


Which of the following should be insereted indepently for the program to compile:

a) import static java.lang;
b) import static java.lang.Integer;
c) import static java.lang.Integer.*;
d) import static java.lang.Integer.*_VALUE;
e) import static java.lang.MAX_VALUE;
f) None of the above

According to me the answer should be b), c) and e).
But answers are c) and e).
Can somebody please explain why is it not b)?

Thanks.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure?

e doesn't make any sense.

You use static imports to import the static members of classes and interfaces.

So c is the one that works.

Even though you don't need to add any imports.
[ April 02, 2007: Message edited by: Keith Lynn ]
 
Lovleen Gupta
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya, thats right.
Even if there are no import statements, the code works fine..
But the question is -- what can be added?
and the answers are c&e .
Please help.
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you mistype e?

If e is import static java.lang.Integer.MAX_VALUE;, that will work.
 
Lovleen Gupta
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya, m sorry for the mistyping..you are correct.
My question is why is b not the correct option?
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gupta,

Given>

b) import static java.lang.Integer;
c) import static java.lang.Integer.*;

If you got C as answer. Why you want to select b ?

By C) import static java.lang.Integer.*;
its clear that they have (.*) syntax to include all static things in One class.

What do you want to tell compiler by selecting b:
Like Integer is a static Object ??(you gone wrong here)

Its more a disign issue: Why didn't they included the kind of
import static java.lang.Integer; to grant permission to access all static in it.(They have n't given it). Probably to make things simple.

1)They might have split the import string with "." and
2)Process Last Token : to identify static members(in the prev token Class.)
 
Hang a left on main. Then read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic