So, here is a piece of my abstract class:
abstract public void insert(Object obj);
And here is the implementation in a class that extends it:
public void insert(User u){
try{
String sql = "INSERT INTO " + TABLE + " (username, assword) VALUES ("+u.getUsername()+", " +u.getPassword()+")";
conn.execSQL(sql);
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
conn.close();
}
}
and Here is the error:
The type — must implement the inherited abstract method —.insert(Object) userDAO.java
Basically, it is saying to me that I didn’t implement any method that is called “insert” and receives an object as parameter. Doesn’t my model “User” count as an object? What am I doing wrong here?
Thanks for your attention.
Ps.: error message on Eclipse while developing an Android App (I don’t know if it changes anything).
Your method signature is incorrect, base and derived methods take different objects. Let me try and explain:
Assume you have a class Base which takes an instance of another class B1 in one of its methods (say m1). Also assume that you have a Derived class Derived1 which overrides the method (m1) in Base with the parameter D1 and similarly a derived class Derived2 which overrides the base method with parameter D2.
Both D1 and D2 implement/extend B1. This will be a problem because of the following scenario:
The above code snippet fails because the m1 method in Derived1 expects a parameter of type D1, but it got D2. Do you now see why this type of parameter casting is not permitted?
Note: It is a good practice to use @override annotation when overriding a method in base (from Java 1.5 specification)