Java println - Whats the layout?

Soldato
Joined
27 Aug 2004
Posts
17,111
Location
Geordieland
Hi guys,

Created a program but havign bothe printing the values out. I know you can use the println function to print a value from a different method to the println as ive seen it used, but i cant remember how to do it.

Its something like
Code:
System.out.println (<method>.<variable>())

Am i just going daft or is this possible? Hd a look on the API and cant see anything of use.

Cheers
 
You could do this:
System.out.println ( object.method() );
or
System.out.println ( object.variable );

Usually you would use a getVariable() method which returns the instance variable, as it makes more sense in OO.
 
You can do System.out.println(identifier.variablename); if your member variables access modifier is set to public. But for proper encapsulation you should usually write a getter method and use System.out.println(identifier.getVariable());
 
Back
Top Bottom