The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Constructors

Posted by Harpreet Singh on December 09, 2000 at 5:58 AM

Sir i have just started learning Java & little bit confused on constructors due to following reasons:-

I thought constructor is a sort of function(because we call it by placing () signs in front of class name & this sign generally represents func. name). If it is a sort of default function for every class then why does following samp.java does not run
-----------------------------------------------------------------
class a
{
a(int i)
{
System.out.println("In Class A");
}
}

class b extends a
{
b()
{
System.out.println("In class b");
}
}

class samp
{
public static void main(String args[])
{
b obj = new b();
}
}

------------------------------------------------------------

This program gives a error for constructor a(). if constructor is made by default for every class then where does it go in this case.

Pl. looking forward for your timely & needy help.

Thanks

Harpreet Singh




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us