Abstract Class A{
A(int)
{
}
}
Class B extends A{
}
now wen i compile class B. i get a error cannot find symbol: symbol is constructor A()
Wat do i have to do now?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Abstract Class A{
A(int)
{
}
}
Class B extends A{
}
now wen i compile class B. i get a error cannot find symbol: symbol is constructor A()
Wat do i have to do now?
When a subclass object is constructed, the superclass's constructor must be invoked - either explicitly or implicitly. In your case, it's invoked implicitly, and implicit constructor is constructor without arguments. But A does not have such a constructor. Hence an error.
By Default only non parametric construstor is called but since class A has parametric constructor you need to call it from class B
To add to what has already been said:
When you make a class which has a constructor with or without parameters, and you do not specifically include a constructor (or several constructors) it is the same thing as saying "only allow the listed constructors". So in your example when B attempts to extend A, the error says that B is attempting to use a constructor that does not exist (the default no parameter one implicitly being called)
Provide the no parameter constructor in class A or construct B with an explicit call to super(int)
ok ..Guyz i took you were suggestion and modified the code as following:
************************************************** ***
public abstract class Zee{
Zee(int x)
{System.out.print("Zee 's constructor is callled///..........");
System.out.print("x value is " + x);
}
}
class MTV extends Zee{
private int a=10;
MTV(int x)
{
super(x);
}
}
import java.io.*;
public class Callo
{
public static void main(String [] args)
{
MTV w= new MTV(2);
}
}
now this Callo class wen compiled pops me error
java 1 class ,interface ,or enum expected
What s going wrong with my Callo class?
Please use code tags when posting code to the forum. Help can be found on the Announcements page.
Was Callo defined in it's own file?