Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!

Nipun Devlekar

+ Follow
since Dec 07, 2005
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nipun Devlekar

Really nice explanation
12 years ago
looking at the code i posted earlier above; i tried to incorporate the coding technique in the following codes.Theere are 3 codes one is super class,one is subclass and one is mainline.I found that i am not able to execute a method of subclass eg new PrintableCharStack(10).input() but am able to do so for super class eg; new PrintableCharStack(10).getInstanceCount().following are the codes

12 years ago
I tried to execute the following code from SCJP book

In the above code the author did not create an object for eg;Good a = new Good() and has directly called the constructor followed by the method.The above does not seem to be the normal convention to write a program.
Can anyone explain to me how the above code gets executed without creating an object reference?
Can one write a method inside a constructor and execute it as we do it for object?I wrote the following code which reported the following errors

errors were
devtest$ javac '}' expected.
^ Statement expected.
void Bad() {
^ Identifier expected.
public static void main(String[] args) {
^ 'class' or 'interface' keyword expected.
public static void main(String[] args) {
4 errors
Can anyone solve my doubt
Thanks in advance
[ December 19, 2005: Message edited by: Nipun Devlekar ]
12 years ago
Thanks for your replies Jeff,its become even clearer now .
12 years ago
Hi Ernest

Thanks for ur reply but I feel more confused now!!
you said ""out" is a public, static member variable of the System class"
and also that "It's an instance of PrintStream" that creates a doubt that
does out belong to PrintStream or does it belong to System and what is the
relation between PrintStream and System class??
Is this code legal-->

PrintStream out = new PrintStream();

Also I found that I cannot compile the legal code you gave without including
the import* statement but I can do so for System.out.println("")
without the import statement.

could you please explain to me why so?following is my code


public class UsePrintOut{

public void doit(){System.out.println("HelloWorld");}

public static void main (String[] args){

UsePrintOut good = new UsePrintOut();
//PrintStream out = System.out;



//hello world output requires the* import statement
//but only hello output does not require the*statement
12 years ago
We can access a method of a class simply using its referrence name
eg:CharStack stack1 = new CharStack()is the object instantiated
stack1.push() (or) CharStack.push() if method is static

But, why do we use two (.)dot operators in order to access println method
can't we just say System.println("hello")

The "out" object is of the PrintStream class .System class extends
Object class .System cannot be instantiated,does it mean it is a static class??To whom does PrintStream class belong to and why dont we use
PrintStream.println("hello") or just out.println("hello") as out is an object of class PrintStream.

Everyting is very confusing can anybody help me clear my doubts please
Thanks in advance!!!
12 years ago
Thanks for your replies
i did not get a stack error but a continuous running screen .
As i am using a unix OS i did not get error;may be stack error reports in DOS .
12 years ago
thanks jeff
i found the code executed smoothly which was the other problem you were
12 years ago
what is wrong in doing this
public class LocalMain{

int a;


public static void main (String[] args){

int new1=9;
float new2=8;

LocalMain good = new LocalMain();

System.out.println("the value for a="+ good.a );

System.out.println("the value for new1="+ new1 );
System.out.println("the value for new2="+ new2 );
System.out.println("the value for Local="+ good );


/*errors that were created while writing program Incompatible type for method. Can't convert java.lang.String
to java.lang.String[].

12 years ago