• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!