View Single Post
Old 04-13-2013, 10:39 AM   #27
Shouka
FFR Veteran
FFR Veteran
 
Shouka's Avatar
 
Join Date: Nov 2006
Posts: 382
Default Re: Teach me CS stuff for interviews

Quote:
Originally Posted by Reincarnate View Post
myPuppy.pissOnFloor();
I lol'd.

But yes you're right. Static methods can be called using the class name and do not require an actual instantiation of an object:

Puppy.getNumPuppies();


Calling an instance method requires an instance of the object:

myPuppy = new Puppy();
myPuppy.pissOnFloor();


Java allows you to call static methods by using an instance of the class but I think doing so is considered bad style:

myPuppy = newPuppy();
myPuppy.getNumPuppies();
__________________
Shouka is offline   Reply With Quote