-
Re: but wait there's more!
"foolguy" <mkyong2002@yahoo.com> wrote:
>
>here u just call Cat's and animal's constructor,why the toString function
>will be called?
>u have not call the toString function...um this mean when u call a class,
>all functions of the class will automatically called? or i got wrong concept?
As far as I know, the only thing that happens when the class is created is
that a constructor is called. [In VB every class has a single "initialize"
method that runs every time the class is instantiated; in Java you have constructors--
and you can have several of these types of routines-- all with the same name,
just with different arguments. The constructor that is used depends on what
arguments you use when you create the new object: Class c = new Class(arguments
here); ]
The ToString method would be called if you did something like this:
System.out.println(c);
Java knows it can't print an object, so it looks for the ToString method
and does whatever it says.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks