• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriding constructors

 
Akhilesh Trivedi
Ranch Hand
Posts: 1599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Saravanan Thirugnanam
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.




 
Saravanan Thirugnanam
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Names of method and constructor can be equal even in the same class


The point is: constructor have no return value.
 
Ramakrishna Nalla
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic