| Author |
refrence variable of object
|
sindura kapur
Greenhorn
Joined: Jul 14, 2008
Posts: 22
|
|
can an object refrence variable be used to call a method like: object a; a.methodname(); instead of object a=new object(); a.methodname();
|
 |
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Joined: Aug 26, 2006
Posts: 4967
|
|
You still need to create the instance, especially if the method you are calling is non static, as it would be with the Object class. The toString() method is a real method in the Object class. Your first statement is probably equivalent to: This is valid. But it could be also done in one step, but you need to ensure the object is created with the new keyword: That pretty much does the equivalent of the first code segment, but in one line. I'm not sure if it looks as good or is as readable, but it's valid. With static methods and properties, you don't need an instance, so you can just do something like this: -Cameron McKenzie [ July 20, 2008: Message edited by: Cameron Wallace McKenzie ]
|
Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
|
 |
 |
|
|
subject: refrence variable of object
|
|
|