Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class ClassicSingleton{private static ClassicSingleton instance = null; p

ID: 3830274 • Letter: P

Question

public class ClassicSingleton{private static ClassicSingleton instance = null; protected ClassicSingleton(){} public static ClassicSingleton getlnstance(){} if(instance==null) {instance = new ClassicSingleton();} return instance;}} Consider the Java code true false - instance = new ClassicSingleton(); will not work because the constructor is protected true false - A class can extend true false - the Singleton object can be accessed even though it is private true false - the Singleton object will be loaded will be created when the class is loaded

Explanation / Answer

1.FALSE

Because we can call a constructor by the subclasses or the other classes that are in same package or namespace.

2.TRUE :
A class can extended until it is declared as public, But we cannot extend the classes which is declared as FINAL.

3. TRUE :
Yes it can be accessed because it is declared withh in the class and a singleton instance is not created until the getInstance() method is called for the first time.

4.TRUE
Singleton objects will be initialized when the class is loaded untill we explicitly refer them by accessing the static method to force that the class is loaded.


Thank you I have provided you the answers based on my knowledge and research.