ManoDestra ManoDestra - 2 months ago 6x
Java Question

Can't compile sub class that implements abstract method from base class

Having problems compiling sub classes of a base class that I've defined that has a single method and each sub class implements the abstract base method, but javac is saying that they don't even though it is quite clearly defined in the sub class. (the base class)

package com.manodestra.db;

import java.sql.ResultSet;
import java.sql.SQLException;

public abstract class DbModel<T extends DbModel> extends Model {
abstract T newInstance(ResultSet rs) throws SQLException;

DbModel extends Model, which only has a generic toString method. (the sub class)

package com.manodestra.csa.db.model.configNew;

import com.manodestra.db.DbModel;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;

public class MenuPermissions extends DbModel<MenuPermissions> {
private final String menuId;
private final String userLevel;

public MenuPermissions(
String menuId,
String userLevel
) {
this.menuId = menuId;
this.userLevel = userLevel;

public String getMenuId() {
return this.menuId;

public String getUserLevel() {
return this.userLevel;

public MenuPermissions newInstance(ResultSet rs) throws SQLException {
return new MenuPermissions(

Compilation Error

[javac] Compiling 487 source files to C:\Media\Code\manodestra_java\bin
[javac] C:\Media\Code\manodestra_java\src\com\manodestra\csa\db\model\configNew\
error: MenuPermissions is not abstract
and does not override abstract method newInstance(ResultSet) in DbModel
[javac] public class MenuPermissions extends DbModel<MenuPermissions> {
[javac] ^

Anyone see what the problem is here? I'm guessing that I'm overlooking something really simple.

Further info on requirements:

I'm building an entity framework that generates model objects from a given database. MenuPermissions above is one such model object (auto-generated by a class that I've written called GenerateModel). I want each model to have a method that will allow me to get a new instance of each objecct type based on a resultset, which will populate the object accordingly and return it. Ideally, it should be a static method, but I've tried it as a concrete method for the moment as I need to enforce its existence in each sub class of DbModel. Hope that makes sense.


Your abstract method newInstance has package access, I don't know if that was intended but if it is in a different package then then you would get an error.


So the abstract method in the parent class can not be resolved since it is not declared a public. Remedy is to add public to the method definition or move move the child class into the same package as the parent class :-D