gpt4 book ai didi

java - 使用私有(private)构造函数扩展类

转载 作者:行者123 更新时间:2023-12-02 16:36:13 26 4
gpt4 key购买 nike

是否可以使用不可见构造函数扩展一个类,而不必知道该构造函数的作用并再次实现它?

import java.sql.DriverManager;

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

}

最佳答案

你不能扩展 DriverManager ,但您可以改为实现 DataSource

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.

关于java - 使用私有(private)构造函数扩展类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62670689/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com