File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overriding constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overriding constructors" Watch "Overriding constructors" New topic
Author

Overriding constructors

Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1558
Constructors can not be overridden.

What if I do write a method in the subclass with the same name as that of parent class?
[ July 22, 2005: Message edited by: Akhil Trivedi ]

Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Saravanan Thirugnanam
Greenhorn

Joined: Jan 19, 2005
Posts: 20
Originally posted by Akhil Trivedi:

What if I do write a method in the subclass with the same name as that of parent class?



You can not write a method with the same name as that of parent class. It will give a Compile time error.


saravanan T
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Originally posted by Saravanan Thirugnanam:


You can not write a method with the same name as that of parent class. It will give a Compile time error.






Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Saravanan Thirugnanam
Greenhorn

Joined: Jan 19, 2005
Posts: 20
Hi Barry,

with that post i actually meant to say that you cannot override the constructor for the base class in the child class.(see this code fragment)
Georgy Bolyuba
Ranch Hand

Joined: Feb 18, 2005
Posts: 162
Names of method and constructor can be equal even in the same class


The point is: constructor have no return value.


SCJP 1.4 (100%) Done.<br />SCJD (URLyBird 1.2.3 Started)
Ramakrishna Nalla
Ranch Hand

Joined: Apr 21, 2005
Posts: 61
Constructor only belongs to class...they can't be overlaoded or overrided..Because constructors not inherited to subclasses...

Overloading and overriding possible only when the members inherited to
sublcass.

constructor:
In my view constructor are not class memebers, so not inherited to subclasses

methods:
Methods intherited to subclass(of course only public and default also final)so can be overloaded and overrided.
final methods only overloaded, can't be overrided

instance variables:
inherited to subclasses, if subclass defines same variable then subclass hides(overrides) the inherited variable

Go through this followig code you will be more clearer...( I AM SURE)



Regards
RamaKrishna Nalla

[ July 24, 2005: Message edited by: Ramakrishna Nalla ]
[ July 24, 2005: Message edited by: Ramakrishna Nalla ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overriding constructors