Difference between an abstract class and an interface?

An Abstract class is a class with some common/certain implementations and defines abstraction for other services which are implemented in its concrete sub classes, whereas interface only have method declaration with zero implementations. The difference between Abstract class and An Interface is that if u call Abstract class then u have to call all method of that particular Abstract class but if u call an Interface then it is not necessary that u call all method of that particular interface. An abstract class is a special kind of class that cannot be instantiated. So the question is why we need … Click here to continue…..

Where and how can you use a private constructor?

Private constructor is used if you do not want other classes to instantiate the object and to prevent subclassing. The instantiation is done by a public static method (i.e. a static factory method) within the same class. Used in the singleton design pattern. Used in the factory method design pattern e.g. java.util.Collections class Used in utility classes e.g. StringUtils etc.

What are access modifiers?

Modifier Used with Description public Outer classes, interfaces, constructors, Inner classes, methods and field variables A class or interface may be accessed from outside the package. Constructors, inner classes, methods and field variables may be accessed wherever their class is accessed. protected Constructors, inner classes, methods, and field variables. Accessed by other classes in the same package or any subclasses of the class in which they are referred (i.e. same package or different package). private Constructors, inner classes, methods and field variables, Accessed only within the class in which they are declared No modifier : (Package by default). Outer classes, … Click here to continue…..