aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can someone explain the error @ Line-03 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Can someone explain the error @ Line-03" Watch "Can someone explain the error @ Line-03" New topic
Author

Can someone explain the error @ Line-03

Shanel Jacob
Ranch Hand

Joined: Jun 18, 2006
Posts: 112
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

Joined: Aug 03, 2002
Posts: 7729
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 ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
abhijit Ohal
Ranch Hand

Joined: Mar 10, 2006
Posts: 64
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

Joined: Jun 18, 2006
Posts: 112
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

Joined: Jun 15, 2005
Posts: 4


Try this avoid compilation error.
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Constructor
saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689


hope you can understand now

regards
cinux


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
Shanel Jacob
Ranch Hand

Joined: Jun 18, 2006
Posts: 112
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

Joined: Aug 03, 2002
Posts: 7729
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
 
subject: Can someone explain the error @ Line-03