Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

Q: Constructors Polymirphisms

Thread view: 
Omer - 05 Apr 2007 07:42 GMT
Hi All,
In my class I'd like to have 2 constructors with different signature
(arguments). I'd like one to call the other, something like the
following example.

//------------------------------------------------------------------
import java.awt.Point;
public class MyClass {
    Point pt;
//------------------------------------------------------------------
    public MyClass (int x, int y) {
        pt = new Point(x, y);
    }
//------------------------------------------------------------------
    public MyClass () {
        MyClass (0, 0);// <=== error: cannot resolve symbol. :-(
    }
//------------------------------------------------------------------
}
//------------------------------------------------------------------

This code fails on "cannot resolve symbol." on the marked line.
Any suggestion?
TIA,
Omer.
Lucas - 05 Apr 2007 09:31 GMT
> This code fails on "cannot resolve symbol." on the marked line.
> Any suggestion?
> TIA,
> Omer.

public MyClass () {
  this (0, 0);
}
Lew - 05 Apr 2007 14:20 GMT
Omer wrote:
>  public MyClass () {
>    MyClass (0, 0);// <=== error: cannot resolve symbol.  :-(
>  }
>> This code fails on "cannot resolve symbol." on the marked line.
>> Any suggestion?

Don't embed TAB characters in Usenet posts.

> public MyClass () {
>    this (0, 0);
> }

Side note to the OP: this is not polymorphism but constructor overloading.
Polymorphism involves method overrides, which don't happen with constructors.

Why'n'cha check out the Wikipedia entry for "Type polymorphism"?

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.