Premium

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



Question : Given:

Which statement is true?
  : Given:
1. Both p and s are accessible by obj.
2. only s is accessible by obj.
3. Both r and s are accessible by obj.
4. p, r, and s are accessible by obj.

Correct Answer : 2
Explanation:

p is not public in p1.Acc; cannot be accessed from outside package
r has protected access in p1.Acc







Question : You are developing a banking module.
You have developed a class
named ccMask that has a maskcc method.

Given the code fragment as shown in image:
  : You are developing a banking module.
1. A,B
2. B,C
3. C,D
4. A,D



Correct Answer : 2

Explanation:
option A : In this we are doing substring for StringBuilder instance, however not using returned string. Hence, result will be mask string + entire credit card number.
option B : We are concatenation mask string and last 4 digists. Hence, will return correct result.
option C : We have used append method of StringBuilder class to append mask string and last 4 digits. It will work perfectly.
option D : It will append both entire mask string and full credit card number. (Hence, not a correct solution)







Question : Given the following code:


public static void main(String args[]){

String[] planets = {"Mercury" , "Venus", "Earth" , "Mars"};

System.out.println(planets.length);
System.out.println(planets[1].length());
}

What is the output?



  : Given the following code:
1. 4

2. 3

3. 4

4. 4

5. 4



Correct Answer : 4
Explanation: First print statement will print the size of array, which is 4 and second print statement will print size of second element in array which is "Venus"
which is 5




Related Questions


Question : Given the code fragment. What is the result?
  : Given the code fragment. What is the result?
1. 10 : 10
2. 5 : 5
3. 5 : 10

4. Compilation fails




Question : Given the code fragment:

7. StringBuilder sb1 = new StringBuilder("Duke");
8. String str1 = sb1.toString();
9. //Insert code here
10. System.out.println(str1==str2);

Which code fragment, when inserted at line 9, enables the code to print true?

  : Given the code fragment:
1. String str2 = str1;
2. String str2 = newString (str1);
3. String str2 =sb1. toString ();
4. String str2 = "Duke";




Question : Given the code fragment: Assume that the system date is June , . What is the result?

LocalDate date1 = LocalDate.now();
LocalDate date2 = LocalDate.of(2014,6,20);
LocalDate date3 = LocalDate.parse("2014-06-20", DateTimeFormatter.ISo_DATE);
System.out.println("date1 = " + date1);
System.out.println("date2 = " + date2);
System.out.println("date3 = " + date3);

  : Given the code fragment: Assume that the system date is June , . What is the result?
1.
date1=2014-06-20
date2=2014-06-20
date3=2014-06-20
2.
date1=06/20/2014
date1=2014-06-20
date1=Jun 20, 2014
3. Compilation Fails
4. A DateParseException is thrown at runtime.



Question : Given the code fragment: What is the result?

public static void main(String args[]){
int ii=0;
int jj=7;
for(ii=0; ii System.out.print(ii + " ");
}

  : Given the code fragment: What is the result?
1. 2 4
2. 0 2 4 6
3. 0 2 4
4. Compilation Fails




Question : Given: What is the result?
  : Given: What is the result?
1. ns = 50 s =125
ns = 125 s = 125
ns = 100 s = 125
2. ns = 50 s =125
ns = 125 s = 125
ns = 0 s = 125
3. ns = 50 s =50
ns = 125 s = 125
ns = 100 s = 100
4. ns = 50 s =50
ns = 125 s = 125
ns = 0 s = 125





Question : Given the code from the Greeting.Java file:

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

Which set of commands prints Hello Duke in the console?

  : Given the code from the Greeting.Java file:
1. javac Greeting
java Greeting Duke
2. javac Greeting.java Duke
java Greeting
3. javac Greeting.java
java Greeting Duke
4. javac Greeting.java
java Greeting.class Duke