More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Ans. Because Singleton implementation doesn't restrict it from cloning and hence we can have multiple objects when we actually don't intend it to have multiple objects.
Help us improve. Please let us know the company, where you were asked this question :
Ans. public class StackUsingArrayList {
public static void main(String[] args) {
List list = new ArrayList();
list.add("A");
list.add("B");
list.add("C");
Ans. No, if required we should only have final variables. Bean scoped singleton means that only one instance of the bean will be created and will be shared among different requests and hence instance variables will get shared too.
Help us improve. Please let us know the company, where you were asked this question :
Ans. No. The whole idea of default method is to provide a default definition in case the implementing class intend to provide definition for only some of the methods. Making any of the interface method private would restrict it from being implemented by the implementing class. So default method is an option to provide implementation and not restricting a new definition.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Java 8 allowed for method implementation using default methods in interfaces. As those default methods could contain complex logic and might need organizing the logic into multiple methods, they have allowed for private methods.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Encapsulation facilitate hiding and restricted access and hence more of a security feature. Encapsulation is definitely a great feature as when applications expand criss cross communication between objects / modules could lead to blunders.
Inheritance facilitates code reuse.
Polymorphism comprise of method overloaded ( which to me is negligible usage ) and method overriding. Method overriding is of great usage as it facilitates concept of interfaces and plugin development.
So it’s Security / Organization vs
Code Reuse / Support for other features like overriding vs
Contracts / Plugin Development facilitating the creation of frameworks / libraries.
Which is more important may vary from application to application , its scale , its use , its sensitivity etc.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Method overloading / static polymorphism compared to method overriding / runtime polymorphism has very limited usage as it just opens up an alternate way of defining a different method with the same name.
Method Overriding on other hand opens up many other features like contracting , interfacing , pluging development and hence development of libraries and frameworks.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Encapsulation facilitates security by hiding data and logic whereas Abstraction simplifies organization of data and related logic.
As applications scale, both concepts are required for easy management and maintenance. Encapsulation for security and criss cross communication between objects / modules will make it vulnerable. and Abstraction for better organization that enables better understanding of application code and easy maintainability.
Help us improve. Please let us know the company, where you were asked this question :
Q869. Find minimum operations required to convert one string to another. Allowed operation :Insertion Deletion Replace, all operational costs are same.