This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Whizlab, static import question

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



Which of the following set of import will allow the following
class to compiler and run without errors?





Select 2 options:


[A]
import java.lang.System.*;
import static xyz.Test.Utilities;
import static xyz.Test.Inner;

[B]
import static java.lang.System.out;
import static xyz.Test.*;

[C]
import static java.lang.System.out.*;
import static xyz.Test.*;

[D]
import static java.lang.System.*;
import static xyz.Test.Utilities;
import xyz.Test.Inner;

[E]
import static java.lang.System.*;
import static xyz.Test.Utilities;
import static xyz.Test.Inner;

[F]
import static java.lang.System.out;
import static xyz.Test.Utilities;
import xyz.Test.Inner;




Given Answer is B, E
I say "D" and "F" are also correct.

The rationale behind Whizlab answer is "By default class enclosed enum are static"

Please correct me!!!


Regards,
cmbhatt
[ April 16, 2007: Message edited by: Chandra Bhatt ]
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

actually we can import a static nested class and enum declared in a class by writing both the following statements

why this is happening i dont know
import static xyz.Test.*; //both Inner enum and static class Utilities are getting imported,and other static variable or method if decalred in Test class are also imported.

same is happening i we write
import xyz.Test.*; //both Inner enum and static class Utilities are getting imported,but if there is some other static method or variable in Test class it will not be imported.

Why so?
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Saran,


Saran says :
same is happening i we write
import xyz.Test.*; //both Inner enum and static class Utilities are getting imported,but if there is some other static method or variable in Test class it will not be imported.



Nay, I would have to disagree with you here, you just forget the importance
of static import. When you do static import only static members of that class are imported. If not so (as you say) what would be difference between static import and plain import statements.



Regards,
cmbhatt
 
sharan vasandani
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i know the difference between static and normal import.

but i am saying that for static nested classes and enums,using ne king of import is not making difference why so?
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Saran,

To be or not to be! this is the question!!!

Let us see what others say!


Regards,
cmbhatt
[ April 16, 2007: Message edited by: Chandra Bhatt ]
 
Something must be done about this. Let's start by reading this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic