Correct Answer : Get Lastest Questions and Answer : Explanation: Counter++ will be executed only once because of the else if constructs.
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]
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.