Premium

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



Question : You have been given below code

interface Pet { }
class Dog implements Pet { }
public class Beagle extends Dog{ }

Which three are valid?

A. Pet a = new Dog();
B. Pet b = new Pet();
C. Dog f = new Pet();
D. Dog d = new Beagle();
E. Pet e = new Beagle();
F. Beagle c = new Dog();

  : You have been given below code
1. A,B,C
2. C,D,E
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D,E
5. B,C,F



Correct Answer : Get Lastest Questions and Answer :
Explanation:
Not B
Not C: Pet is abstact, cannot be instantiated.
Not F: incompatible type. Required Beagle, found Dog.






Question : Given the following classes:

public class ColorTest {
public static void main(String[] args) {
String[] colors = { "red", "blue", "green", "yellow", "maroon", "cyan" };
int count = 0;
for (String c : colors) {
if (count >= 4) {
break;
} else {
continue;
}
if (c.length() >= 4) {
colors[count] = c.substring(0, 3);
}
count++;
}
System.out.println(colors[count]);
}
}

What is the result?


  : Given the following classes:
1. Yellow
2. Maroon
3. Access Mostly Uused Products by 50000+ Subscribers
4. A StringIndexOutOfBoundsException is thrown at runtime.




Correct Answer : Get Lastest Questions and Answer :

Explanation: The line, if (c.length() >= 4) {, is never reached. This causes a compilation error.
Note: The continue statement skips the current iteration of a for, while , or do-while loop. An
unlabeled break statement terminates the innermost switch, for, while, or dowhile
statement, but a labeled break terminates an outer statement.





Question : Which two actions will improve the encapsulation of a class?
A. Changing the access modifier of a field from public to private
B. Removing the public modifier from a class declaration
C. Changing the return type of a method to void
D. Returning a copy of the contents of an array or ArrayList instead of a direct reference

  : Which two actions will improve the encapsulation of a class?
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D





Correct Answer : Get Lastest Questions and Answer :
Explanation:





Related Questions


Question : Given: What is the result?




  : Given: What is the result?
1. C B A
2. C
3. A B C
4. Compilation fails at line n1 and line n2






Question : Given the code fragment:

What is the result?

  : Given the code fragment:
1. [Robb, Rick, Bran]
2. [Robb, Rick]
3. [Robb, Bran, Rick, Bran]
4. An exception is thrown at runtime.



Question :

1. Replace line n2 with
e.name="Joe";
e.contract=true;
e.salary=100;

2. Replace line n2 with
this.name="Joe";
this.contract=true;
this.salary=100;

3. Replace line n1 with
this.name=new String("Joe");
this.contract=new Boolean(true);
this.salary=new Double(100);

4. Replace line n1 with
name="Joe";
contract=TRUE;
salary=.0f;

5. Replace line n1 with
this("Joe", true, 100);

  :
1. 1,2
2. 1,3
3. 2,4
4. 4,5
5. 3,5







Question : What is the result?`
 : What is the result?`
1. 97 98
99 100 null null null
2. 97 98
99 100 101 102 103
3. Compilation Fails.
4. A NullPointerException is thrown at runtime.
5. An ArraylndexoutofBoundsException is thrown at runtime.



Question : Given the code fragment:

int x=100;
int a = x++;
int b = ++x;
int c = x++;
int d = (a System.out.println(d);

What is the result?

  : Given the code fragment:
1. 100
2. 101
3. 102
4. 103
5. Compilation Fails






Question : Given the following main method:

public static void main(String args[]){
int num = 5;
do{
System.out.println(num-- + " ");
}while(num ==0);
}

What is the result ?

 : Given the following main method:
1. 5 4 3 2 1 0
2. 5 4 3 2 1
3. 4 2 1
4. 5
5. Nothing is printed