Nipun Devlekar

Greenhorn
+ Follow
since Dec 07, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
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 Good.java
Good.java:5: '}' expected.
System.out.println("Constructor");
^
Good.java:7: Statement expected.
void Bad() {
^
Good.java:14: Identifier expected.
public static void main(String[] args) {
^
Good.java:14: 'class' or 'interface' keyword expected.
public static void main(String[] args) {
^
4 errors
Can anyone solve my doubt
Thanks in advance
NIPUN.
[ 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();
out.println("Hello");

Also I found that I cannot compile the legal code you gave without including
the import java.io.* 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

//UsePrintOut

//import java.io.*;
public class UsePrintOut{

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

public static void main (String[] args){

UsePrintOut good = new UsePrintOut();
//PrintStream out = System.out;
//out.println("Hello");
good.doit();

}

}

//hello world output requires the java.io.* import statement
//but only hello output does not require the jva.io.*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
saying??
12 years ago
what is wrong in doing this
//LocalMain
public class LocalMain{

//fields
int a;


//mainline

public static void main (String[] args){

//fields
int new1=9;
float new2=8;


//instance
LocalMain good = new LocalMain();

//OUTPUT
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 );
good.main("hello");

}
}


/*errors that were created while writing program

LocalMain.java:26: Incompatible type for method. Can't convert java.lang.String
to java.lang.String[].
good.main("hello");

*/
12 years ago