-
Error during compiling
When I compile it returns to me the error:
Code:
Cars.java:12: Object() in java.lang.Object cannot be applied to (java.lang.String)
super(str);
^
1 error
this is my code:
Code:
public class Cars{
private int free;
public Cars() {
}
public Cars(String str) {
super(str);
}
}
any ideas?
-
You are trying to call the constructor of object with a String.
The Object class only has a single empty constructor so you can only use
Code:
public Cars(String str) {
super();
}
If you want to keep the value of str you will need to store it in a member variable which you define in the Cars class.
Hope that sorts you out. :)
-
Hi there,
If i'm not mistaken, what your code does is that it parses the variable str of type String to this class's superclass' constructor. However, you didn't really define your own superclass? Thus, you are using java's object class, which does not have a constructor that accepts a string value. Try defining your own superclass?
Yi Wei.