Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can someone explain the error @ Line-03

 
Shanel Jacob
Ranch Hand
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • 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();
}
}
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
abhijit Ohal
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Narendra Jain
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Try this avoid compilation error.
 
wise owen
Ranch Hand
Posts: 2023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Constructor
 
saikrishna cinux
Ranch Hand
Posts: 689
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


hope you can understand now

regards
cinux
 
Shanel Jacob
Ranch Hand
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic