• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inhertance

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we inherit the constructor in a Class?please give one
example.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by shruti patel:
Can we inherit the constructor in a Class?

No
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How would you test whether constructors are inherited? Tell us what code you'd need to do so. Once you have the code, you can compile and run it, to see what happens.
 
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By default constructors are not inherited. You can call a superclass constructor in an inheritance chain by using the "super." keyword.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by shruti patel:
Can we inherit the constructor in a Class?please give one
example.


For constructor we can do one thing.
Overloading!!
A example from SCJP

The inhertance is used for a class.
(Sorry i'm poor about english!)
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
constructors are not inherited

here's the code to support this



this is ConstructorTry class in A package

There is another class ConstructorTry in package B



the line marked will give an error that there is no constructor in Constructor try that takes a String. If the constructor of A.ConstructorTry was inherited then the line would have compiled as A.ConstructorTry has a constructor which takes a String and B.ConstructorTry is a sub-class of A.ConstructorTry.

Hope this is OK.......
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic