91-100 Flashcards
Is there a way to increase the size of an array after its declaration?
Arrays are static and once we have specified its size, we can’t change it. If we want to use such collections where we may require a change of size (no of items), we should prefer vector over array.
If an application has multiple classes in it, is it okay to have a main method in more than one class?
If there is main method in more than one classes in a java application, it won’t cause any issue as entry point for any application will be a specific class and code will start from the main method of that particular class only.
I want to persist data of objects for later use. What’s the best approach to do so?
The best way to persist data for future use is to use the concept of serialization.
What is a Local class in Java?
In Java, if we define a new class inside a particular block, it’s called a local class. Such a class has local scope and isn’t usable outside the block where its defined.
String and StringBuffer both represent String objects. Can we compare String and StringBuffer in Java?
Although String and StringBuffer both represent String objects, we can’t compare them with each other and if we try to compare them, we get an error.
Which API is provided by Java for operations on set of objects?
Java provides a Collection API which provides many useful methods which can be applied on a set of objects. Some of the important classes provided by Collection API include ArrayList, HashMap, TreeSet and TreeMap.
Can we cast any other type to Boolean Type with type casting?
No, we can neither cast any other primitive type to Boolean data type nor can cast Boolean data type to any other primitive data type.
Can we use different return types for methods when overridden?
The basic requirement of method overriding in Java is that the overridden method should have same name, and parameters.But a method can be overridden with a different return type as long as the new return type extends the original.
What’s the base class of all exception classes?
In Java, Java.lang.Throwable is the super class of all exception classes and all exception classes are derived from this base class.
What’s the order of call of constructors in inheritance?
In case of inheritance, when a new object of a derived class is created, first the constructor of the super class is invoked and then the constructor of the derived class is invoked.