• Post Reply Bookmark Topic Watch Topic
  • New Topic

static imports: from sun's pre-assesment  RSS feed

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

[Q.no 37, sun pre-assesment test.. they dont give the answers ]



When class StaticStuff has been compiled, what is the result when you attempt to compile class FindStatic?

The code compiles.
Compilation fails due to an error on line 1.
Compilation fails due to an error on line 4.
Compilation fails due to an error on line 5.
Compilation fails due to an error on line 6.
Compilation fails due to errors on multiple lines.




I had chosen option1 but I think I was wrong...
Is it the option three?
Static import only imports the static member so there's no way to instantiate StaticStuff in FindStatic??

Thanks...
 
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have chosen the correct answer, we can not import like

import static x.StaticStuff.*;

Thanks!
Sunny
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct answer is: Compilation fails due to an error on line 5.
The compiler cannot recognize the StaticStuff.
Need to add import com.test.StaticStuff;
 
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please anybody clearify the above given problem and state why?
 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please anybody clearify the above given problem with solutions and state why?
 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please anybody clearify the above given problem with solutions and state why?
 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please anybody clearify the above given problem with solutions and state why?
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is on line 5.
ss = new StaticStuff();

Although you have imported the static members, but to instantiate the StaticStuff class, you need to use the package name. Try using

ss = new x.StaticStuff();

It will compile fine.

Hope this helps
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!