tags:

views:

114

answers:

5

I have a class that creates the object of type Smo. The object then calls a static method from another class. The static method requires that I pass the object to it that is calling it. How do I designate the calling object as the parameter to pass.

For example:

class Smo {    
    Smo() {
    }

    void sponge() {
        car.dancing(??????);    //////< ----------- how do I refer to self?
    }

    void dance() {
        //// do a little dance
    }
}

class Car() { 
    Car() {
    }

    dancing(Smo smo) {    
        smo.dance();
    }    
}
+13  A: 

Use the this keyword.

car.dancing(this);
Mark Peters
Duh. :: Kicks self:: I'll give you your check in 12 minutes. Thank you :)
Doodle
+5  A: 

use the keyword this

fuzzy lollipop
+3  A: 

Use this to have an object refer to itself. So,

car.dancing(this);
Ben J
+1  A: 

yup: car.dancing(this);

Echidna
A: 

been there done (this) :D

frictionlesspulley