Question : Which statement is true about the default constructor of a top-level class?
1. It can take arguments. 2. It has private access modifier in its declaration. 3. Access Mostly Uused Products by 50000+ Subscribers 4. The default constructor of a subclass always invokes the no-argument constructor of its superclass.
Correct Answer : Get Lastest Questions and Answer : Explanation: In both Java a "default constructor" refers to a constructor that is automatically generated by the compiler if no constructors have been defined for the class. The default constructor is also empty, meaning that it does nothing. A programmer- defined constructor that takes no parameters is also called a default constructor.
Question : You have been given below code
List colors = new ArrayList(); colors.add("green"); colors.add("red"); colors.add("blue"); colors.add("yellow"); colors.remove(2); colors.add(3, "cyan"); System.out.print(colors);
Correct Answer : Get Lastest Questions and Answer : Explanation: First the list [green, red, blue, yellow] is build. The blue element is removed: [green, red, yellow] Finally the element cyan is added at then end of the list (index 3). [green, red, yellow, cyan]
Question : The catch clause argument is always of type .
A. Exception B. Exception but NoT including RuntimeException C. Throwable D. RuntimeException E. CheckedException
Correct Answer : Get Lastest Questions and Answer : Explanation: Because all exceptions in Java are the sub-class of java.lang.Exception class, you can have a single catch block that catches an exception of type Exception only. Hence the compiler is fooled into thinking that this block can handle any exception. See the following example: try { // ... } catch(Exception ex) { // Exception handling code for ANY exception } You can also use the java.lang.Throwable class here, since Throwable is the parent class for the application-specific Exception classes. However, this is discouraged in Java programming circles. This is because Throwable happens to also be the parent class for the non-application specific Error classes which are not meant to be handled explicitly as they are catered for by the JVM itself. Note: The Throwable class is the superclass of all errors and exceptions in the Java language. only objects that are instances of this class (or one of its subclasses) are thrown by the Java Virtual Machine or can be thrown by the Java throw statement. A throwable contains a snapshot of the execution stack of its thread at the time it was created. It can also contain a message string that gives more information about the error.
1. Compilation fails. 2. The third argument is given the value null. 3. Access Mostly Uused Products by 50000+ Subscribers 4. The third argument is given the value zero. 5. The third argument is given the appropriate false value for its declared type.