• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Static import

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a question. The book has the following static import usage:

import static java.lang.System.out;
public class TestStaticImport {
public static void main(String[] args) {
out.println("Hello"); // by the book
println("Hello"); // will this also work?
}
}

The book says the first statement, out.println, works. Does the second statement, just the println without the out, work?
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happened when you tried to compile and run it?
 
Tobie Henderson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This may sound lame, but I don't have J2Se installed in my computer. Sorry guys.

Originally posted by Ulf Dittmer:
What happened when you tried to compile and run it?

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

This will not work cause
println() is a method not of System class but of printWriter class
when you say
import static java.lang.System.out;

out is a static member of class System so your are saying that
I will not always like to use System and my program should be smart enough to understand that out is memeber of System class and use it.
So this
out.println("Hello"); // by the book
and
println("Hello"); // will this also work?

will never work

Hope that clears your doubt.
and if you want to clear this exam make sure you have java 5 installed on your system and you try and do as much practical as possible that will clear your air for a lot of stuff.
 
He's giving us the slip! Quick! Grab this tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic