Scjp 6.0 _ Java _ Level 1

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By LanFang
L
LanFang
Community Contributor
Quizzes Created: 2 | Total Attempts: 669
| Attempts: 494 | Questions: 10
Please wait...
Question 1 / 10
0 %
0/100
Score 0/100
1. Given:     int x = 0;     int y = 10;     while (x < 5) {         y--;         ++x;     } ;     System.out.print(x + "," + y); What is the result? 

Explanation

The given code initializes x to 0 and y to 10. It then enters a while loop that continues as long as x is less than 5. Inside the loop, y is decremented by 1 and x is incremented by 1. This process continues until x becomes 5. After the loop, the values of x and y are printed, which are 5 and 5 respectively. Therefore, the correct answer is 5,5.

Submit
Please wait...
About This Quiz
Java Quizzes & Trivia

This 'SCJP 6.0 _ JAVA _ Level 1' quiz assesses knowledge of Java programming fundamentals. Questions cover string manipulation, control structures, loop constructs, and variable declarations, providing a... see morepractical evaluation for learners aiming to improve or test their Java skills. see less

2. Given: public class TestString1 {     public static void main(String[] args) {         String str = "420";         str += 42;         System.out.print(str);     } } What is the output? 

Explanation

The output of this code is "42042". The code starts with a string "420" and then uses the += operator to concatenate the number 42 to the string. This results in the final string "42042".

Submit
3. Given: class Alligator {     public static void main(String[] args) {         int[] x[] = { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } };         int y[][] = x;         System.out.print(y[2][1]);     } } What is the result? 

Explanation

The code declares and initializes a 2D array called "x" with three rows and different number of columns in each row. Then, it declares another 2D array called "y" and assigns "x" to it. Finally, it prints the value at index [2][1] of array "y", which is 7. Therefore, the result is 7.

Submit
4. Given: public class Barn {     public static void main(String[] args) {         new Barn.go("hi", 1);         new Barn.go("hi", "world", 2);     }     public void go(String... y, int x) {         System.out.print(y[y.length - 1] + " ");     } } What is the result? 

Explanation

The code will not compile because the method go() is not static, but it is being called from the static main() method without creating an instance of the Barn class. The go() method should either be made static or an instance of the Barn class should be created before calling the go() method.

Submit
5. Given:     String[] elements = {"for", "tea", "too"};     String first = (elements.length>0) ? elements[0] : null; What is the result? 

Explanation

The correct answer is "The variable first is set to elements[0]." In this code, the ternary operator is used to check if the length of the elements array is greater than 0. If it is, the value of the first element in the array (elements[0]) is assigned to the variable first. Otherwise, null is assigned to first. Since the length of the elements array is 3, the variable first will be set to the value of elements[0], which is "for".

Submit
6. Given: 35. String #name = "Jane Doe"; 36. int $age = 24; 37. Double _height = 123.5; 38. double ~temp = 37.5;  Which two statements are true? (Choose two.) 

Explanation

Line 35 will not compile because the variable name cannot start with a special character (#).

Line 38 will not compile because the variable temp cannot start with a special character (~).

Submit
7. Given: public class Test {     public static void main(String[] args) {         int x = 5;         boolean b1 = true;         boolean b2 = false;         if ((x == 4) && !b2)             System.out.print("1 ");             System.out.print("2 ");         if ((b2 = true) && b1)             System.out.print("3 ");     } } What is the result? 

Explanation

The code first checks if x is equal to 4 and b2 is false, which is false in this case. Therefore, the first if statement is not executed. Then, the code prints "2" because it is outside of the if statement. After that, the code assigns true to b2 and checks if b2 is true and b1 is true, which is true in this case. Therefore, the second if statement is executed and "3" is printed. So, the final output is "23".

Submit
8. Given:     public void go() {         String o = "";         z:         for (int x = 0; x < 3; x++) {             for (int y = 0; y < 2; y++) {                 if (x == 1)break;                 if (x == 2 && y == 1)break z;                 o = o + x + y;             }         }         System.out.println(o);     } What is the result when the go() method is invoked? 

Explanation

The go() method contains two nested for loops. The outer loop iterates from 0 to 2 and the inner loop iterates from 0 to 1. Inside the inner loop, there are two conditions. If x is equal to 1, the inner loop is terminated using the "break" statement. If x is equal to 2 and y is equal to 1, the outer loop is terminated using the "break z" statement. In all other cases, the value of x and y are concatenated to the string "o".

Therefore, when the go() method is invoked, the value of "o" becomes "000120" and it is printed.

Submit
9. Given: 1. class Super{ 2.     private int a; 3.     protected Super(int a){this.a = a;} 4. } ... 11. class Sub extends Super{ 12.     public Sub(int a){super(a);} 13.     public Sub(){this.a = 5;} 14. } Which two, independently, will allow Sub to compile? (Choose two.) 

Explanation

The first change, changing line 13 to "public Sub(){this(5);}", will allow Sub to compile because it calls the constructor of Sub class with an argument of 5.

The second change, changing line 13 to "public Sub(){super(5);}", will also allow Sub to compile because it calls the constructor of the Super class with an argument of 5.

Both of these changes provide a valid way to initialize the Sub class without any compilation errors.

Submit
10. Given: public class Breaker2 {     static String o = "";     public static void main(String[] args) {         z: for (int x = 2; x < 7; x++) {             if (x == 3)                 continue;             if (x == 5)                 break z;             o = o + x;         }         System.out.println(o);     } } What is the result? 

Explanation

The code uses a label "z" to create a labeled loop. The loop iterates from 2 to 6. If the value of x is 3, the continue statement is executed, which skips the current iteration. If the value of x is 5, the break statement with the label "z" is executed, which terminates the loop. Otherwise, the value of x is concatenated to the string "o". In this case, the loop will iterate from 2 to 6, excluding 3 and terminating at 5. Hence, the value of "o" will be "24".

Submit
View My Results

Quiz Review Timeline (Updated): Mar 20, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 20, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jan 03, 2013
    Quiz Created by
    LanFang
Cancel
  • All
    All (10)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Given:...
Given:...
Given:...
Given:...
Given:...
Given:...
Given:...
Given:...
Given:...
Given:...
Alert!

Advertisement