View Full Version : Java help!

12-03-2011, 08:25 AM
This is my first time on this forum and i'm currently taking a programming course in second year computer engineering. I have a exam coming up soon for this course. I need some help with understanding tostring() method. What does it do? Also can someone explain to me overloading and abstract method?

Thanks in advance. <3

12-03-2011, 08:37 AM
Java and JavaScript are two different languages. Which one do you mean?

12-03-2011, 08:52 AM
Java and JavaScript are two different languages. Which one do you mean?

Java. I meant java :)

Old Pedant
12-03-2011, 10:39 AM
Then you need to post in the Java forum. Likely one of the moderators will move this thread.

Are you talking about the default toString()? That is Object.toString()? Or are you talking about overriding toString() for other classes?

As for overloading: It's simply where you have two or more methods with the same name, in the same class, that have different parameter types.

class zam {
int doit( int i ) {...} /*overloaded doit methods */
int doit( string s ) { ... }

Distinct from overriding, where two classes have a method with the same name and parameter types and one class is derived from the other.

class base {
public int doit( int i ) {...}
class child extends base {
public int doit( int i ) { ... } /* this method overrides base.doit */

An abstract class is simply one that acts as the base class for one or more derived classes but can not itself be instantiated. (That is, if you declare

abstract class foo {....};
class bar extends foo { ... };

Then you *can* do bar b = new bar(); but you can *NOT* do foo f = new foo();
This allows you to define the behavior of class derived from foo without needing to allow the user to create a foo object.