• 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

Can someone explain the error @ Line-03

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Father
{
Father(int i) {} // Compiler error here
}

class Son extends Father
{

}

class Family
{
public static void main(String[] args)
{
new Son();
}
}
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Use code tags: , put your code between them.
2) If you get a compile error say which message you are getting. You have compiled it haven't you?
3) What does the error tell you? What don't you understand about the error message?
[ July 16, 2006: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will give compiler time error.

Because Son class didn't provide super constuctor to invoke Father.
Law is
As Super Class didn't have default constuctor , So Its SubClass Must provide constuctor for invoking .

let me know if you want more explanation.

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

I think I kinda understand. Since Son did not declare any constructor, the default will be created by the compiler as follows:



However, Father do not have a no-arg constructor so we cannot compile.

Thanks Abhijit!
[ July 17, 2006: Message edited by: Shanel Jacob ]
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Try this avoid compilation error.
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Constructor
 
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


hope you can understand now

regards
cinux
 
Shanel Jacob
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes the automatically generated Super() is no arg. But the only contructor Father has take in an arg. That's the problem. Thank you all for your replies
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The compiler error is in class Son, not where you indicated in class Father. Class Father compiles perfectly OK.
The message "cannot find symbol: constructor Father()" tells you need a no arg constructor in Father.

So everything was there to solve the problem.
 
reply
    Bookmark Topic Watch Topic
  • New Topic