Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Whizlab, static import question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Whizlab, static import question" Watch "Whizlab, static import question" New topic
Author

Whizlab, static import question

Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707



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 ]

cmbhatt
sharan vasandani
Ranch Hand

Joined: Feb 22, 2007
Posts: 100
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

Joined: Feb 28, 2007
Posts: 1707
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

Joined: Feb 22, 2007
Posts: 100
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

Joined: Feb 28, 2007
Posts: 1707
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Whizlab, static import question