Premium

Oracle Java Programming Certification Questions and Answers (Dumps and Practice Questions)



Question : You have been given following code fragment

String[] cartoons = { "tom", "jerry", "micky", "tom" };
int counter = 0;
if ("tom".equals(cartoons[0])) {
counter++;
} else if ("tom".equals(cartoons[1])) {
counter++;
} else if ("tom".equals(cartoons[2])) {
counter++;
} else if ("tom".equals(cartoons[3])) {
counter++;
}
System.out.print(counter);

What would be printed , when executed ?
 : You have been given following code fragment
1. 1
2. 2
3. Access Mostly Uused Products by 50000+ Subscribers
4. 0




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?

 :  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);


 : You have been given below code
1. [green, red, yellow, cyan]
2. [green, blue, yellow, cyan]
3. Access Mostly Uused Products by 50000+ Subscribers
4. An IndexOutOfBoundsException is thrown at runtime





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]



Related Questions


Question : You have been given following code

public class MyClass {
public static void main(String[] args) {
while(int ii = 0; ii < 2) {
ii++;
System.out.println("ii = " + ii);
}
}
}

What would be result ?


 : You have been given following code
1. ii = 1 ii = 2
2. Compilation fails
3. Access Mostly Uused Products by 50000+ Subscribers
4. The program goes into an infinite loop with no output
5. The program goes to an infinite loop outputting: ii = 1 ii = 1




Question : You have been given following

class Base {
public static void main(String[] args) {
System.out.println("Base " + args[2]);
}
}

public class Sub extends Base {
public static void main(String[] args) {
System.out.println("Overriden " + args[1]);
}
}

 : You have been given following
1. Base 30
2. Overridden 20
3. Access Mostly Uused Products by 50000+ Subscribers
4. Base 30 Overridden 20




Question : You have been given following code

public class ScopeTest {
int j;
int k;

public static void main(String[] args) {
new ScopeTest().doStuff();
}

void doStuff() {
int x = 5;
doStuff2();
System.out.println("x");
}

void doStuff2() {
int y = 7;
System.out.println("y");
for (int z = 0; z < 5; z++) {
System.out.println("z");
System.out.println("y");
}
}
}

Which two items are fields?

A. j
B. k
C. x
D. y
E. z


 : You have been given following code
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,B,C






Question : An unchecked exception occurs in a method dosomething() Should other code be added in the dosomething() method for it to compile and execute?

 : An unchecked exception occurs in a method dosomething() Should other code be added in the dosomething() method for it to compile and execute?
1. The Exception must be caught
2. The Exception must be declared to be thrown.
3. Access Mostly Uused Products by 50000+ Subscribers
4. No other code needs to be added.




Question : Which two statements are true for a two-dimensional array of primitive data type?
A. It cannot contain elements of different types.
B. The length of each dimension must be the same.
C. At the declaration time, the number of elements of the array in each dimension must be specified.
D. All methods of the class object may be invoked on the two-dimensional array.

 : Which two statements are true for a two-dimensional array of primitive data type?
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D




Question : A method is declared to take three arguments. A program calls this method and passes only two arguments. What is the result?

 : A method is declared to take three arguments. A program calls this method and passes only two arguments. What is the result?
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.