• 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

Constructors

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,



i know that Line 2 give an implicit call to the no argument constructor of the parent class instead of the argument constructor.If it will not find the constructor without argument in parent class will give compiler error.

My question is if I put "super(2); at line 1. It is compiling without any error.

I want to know the reason behind.
If someone help me out with.

Thanks
[ March 03, 2008: Message edited by: sandhi mridul ]
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If it will not find the constructor without argument in parent class will give compiler error.

My question is if I put "super(2); at line 1. It is compiling without any error.

I want to know the reason behind.



Not sure what you are asking.... in the first sentence, you mentioned that it is an error because the no-arg constructor doesn't exist.

In the second sentence, you are asking why it works when you use a constructor that does exist?

Doesn't understanding the first sentence, imply an understanding of the second sentence?

Henry
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Henry
I think sandhi wants to ask if we not calling default constructor of Test2 from main method it should not play any role.as we are calling argument constructor.I we make default constructor in class Base or make a call in to super with the arguments specified in Base class it will not give any error.
****************
So why in this condition it is showing error as default constructor is not being called.

Thanks
Deepak
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So why in this condition it is showing error as default constructor is not being called.



Just because you are not calling it, doesn't mean that the compiler don't have to compile the code. After all, how does the compiler know that another class won't call it?

Henry
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic