• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

static imports: from sun's pre-assesment

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic