Search code examples
javaconstructorprivateextends

Extend a class with private constructer


Is it possible to extend a class with a nonvisible constructor without having to know what this constructor do and implement it again?

import java.sql.DriverManager;
    
public class myDriverManager extends DriverManager {
    public myDriverManager() {
        super(); //Fehler: the constructor DriverManager() ist not visible
    }
    
}

Solution

  • You can't extend DriverManager, but you can implement DataSource instead

    NOTE: The DataSource interface, new in the JDBC 2.0 API, provides another way to connect to a data source. The use of a DataSource object is the preferred means of connecting to a data source.