while implementing singleton as:
class MyConnection {
private static MyConnection connection = new MyConnection();
private MyConnection() {
}
public static MyConnection getConnection() {
return connection;
}
}
1)why we give connection
as static?
Is this only due to the fact that getConnection()
is static and we cannot reference non-static in static context or there is any other reason?
2) is it necessary to declare connection
as final?