This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes start() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "start() method" Watch "start() method" New topic

start() method

Sharanya Sharma
Ranch Hand

Joined: Jul 26, 2004
Posts: 54

Please look at this code
public class Tux extends Thread{
static String sName = "vandeleur";
public static void main(String argv[]){
Tux t = new Tux();
public void piggy(String sName){
sName = sName + " wiggy";
public void run(){
for(int i=0;i < 4; i++){
sName = sName + " " + i;

The answer to the above question is given as
Compilation and probably output of "vandelur" but possible output
of "vandeleur 0 1 2 3"

But the start method should be called on an instance. Please let me know if Iam wrong.
Aarti Dahiya

Joined: Aug 07, 2004
Posts: 15
A reference to the object which invokes the non-static method is passed IMPLICITLY to the non-static method.
The method call t.piggy(sName) invokes the method piggy. Apart from the reference t, piggy has its own reference to the object referenced by t. It has been passed implicitly. So, when start() is called it is actually t.start().

SCJP 1.4 (95%)
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: start() method
It's not a secret anymore!