Premium

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



Question : Given the code fragment:

String shirts[][] = new String[2][2];
shirts[0][0]="red";
shirts[0][1]="blue";
shirts[1][0]="small";
shirts[1][1]="medium";

Which code fragment prints red: blue: small: medium?


 :  Given the code fragment:
1. A

2. B
3. C

4. D


Correct Answer : 4

Explanation: Yes, we need embeded for loop. In first iteration of outerloop, inner loop will iterate twice and print the data from same row. In this case it will be red : blue
and in next iteration it will print all the values from second row and will print small:medium . Hence, option 4 is correct.







Question :


A. this.amount = 0;
B. amount = 0;
C. acct (0) ;
D. acct.amount = 0;
E. acct. getAmount () = 0;
F. acct.changeAmount(0);
G. acct.changeAmount(-acct.amount);
H. acct.changeAmount(-acct.getAmount());


 :
1. A,B,C
2. A,C,D
3. D,G,H
4. E,F,G
5. A,E,F



Correct Answer : 3

Explanation: In option D, we are explicitely setting the amount value as 0 and remaining and in option G and H we are passing the same amount with the negation.
Hence, it will make this amount to 0.





Question : Given the code fragment from three files:
Which code fragment, when inserted at line 2 (in third file), enables the code to compile?


package sales;
public class SalesMan { }

package sales.products;
public class Product { }

package market;
//insert code here
public class USMarket {
SalesMan sm;
Product p;
}
 :  Given the code fragment from three files:
1. import sales.*;

2. import java.sales.products.*;
3. import sales;
import sales.products;
4. import sales.*;
import sales.products.*;


Correct Answer : 4

Explanation: You have to import a class explicitely or entire package. In the given option we are not importing classes explicitley. Hence, we need to import entire package and in
option 4 we are doing this.


Related Questions


Question : Given:
class X {}
class Y { Y ( ) { } }
class Z { Z (int i ) { } }
Which class has a default constructor ?

 : Given:
1. X only

2. Y only

3. Z only

4. X and Y
E. Y and Z
5. Y and Z


Question : The protected modifier on a Field declaration within a public class means that the field .
 : The protected modifier on a Field declaration within a public class means that the field .
1. Cannot be modified
2. Can be read but not written from outside the class
3. Can be read and written from this class and its subclasses only within the same package
4. Can be read and written from this class and its subclasses defined in any package





Question : You have been given below code

public class DoBreak1 {
public static void main(String[] args) {
String[] table = { "aa", "bb", "cc", "dd" };
for (String ss : table) {
if ("bb".equals(ss)) {
continue;
}
System.out.println(ss);
if ("cc".equals(ss)) {
break;
}
}
}
}

What would be printed ?

 : You have been given below code
1. aa cc
2. aa bb cc
3. cc dd
4. cc

5. Compilation fails.




Question : You have been given following code

public class Testoperator {
public static void main(String[] args) {
int result = 30 - 12 / (2 * 5) + 1;
System.out.print("Result = " + result);
}
}

What is the result?


 : You have been given following code
1. Result = 2
2. Result = 3
3. Result = 28
4. Result = 29
4. Result = 30





Question : Which three are bad practices?

A. Checking for ArrayIndexoutofBoundsException when iterating through an array to determine when all elements have been visited
B. Checking for Error and. If necessary, restarting the program to ensure that users are unaware problems
C. Checking for FileNotFoundException to inform a user that a filename entered is not valid
D. Checking for ArrayIndexoutofBoundsException and ensuring that the program can recover if one occur
E. Checking for an IoException and ensuring that the program can recover if one occurs

 : Which three are bad practices?
1. A,B,C
2. B,C,D
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,B,D
5. B,C,D




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