Responsive Ads Here

Tuesday, March 17, 2020

ocjp dumps | ocjp 8 dumps | ocjp latest dumps | ocjp certification dumps - set -2

In the series of OCJP certification dumps, This is second set in which 10 most important questions is being covered,  let's  practice these questions.

I will suggest you to first solve all the given questions yourself then only look at the solutions. If you have any doubt in any solution please comment. You can also share your score in comment box below. 


SET-2


1. What will be printed when the following program is run?

package blog;

public class ParameterPass {

  public static void main(String[] args) {
    int i = 0;
    addValue(i++);
    System.out.println(i);
  }

  static void addValue(int i) {
    i += 2;
  }
}

Select the one correct answer.
(a) 0
(b) 1
(c) 2
(d) 3

2.  Which method declarations are valid declarations?
Select the three correct answers.
(a) void compute(int... is) { }
(b) void compute(int is...) { }
(c) void compute(int... is, int i, String... ss) { }
(d) void compute(String... ds) { }
(e) void compute(String... ss, int len) { }
(f) void compute(char[] ca, int... is) { }


3. Given the following code:
package blog;

public class ParameterPassTest1 {

  static void print(Object... obj) {
    System.out.println("Object...: " + obj[0]);
  }

  public static void main(String[] args) {
    // (1) INSERT METHOD CALL HERE.
  }
}
Which method call, when inserted at (1), will not result in the following output from the program:
Object...:  3
Select the one correct answer.
(a) print("3", "1", "1");
(b) print(3, 1, 1);
(c) print(new int[] {3, 1, 1});
(d) print(new Integer[] {3, 1, 1});
(e) print(new String[] {"3", "1", "1"});
(f) print(new Object[] {"3", "1", "1"});

4.  Which of the following are reserved keywords?
Select the three correct answers.
(a) public
(b) String
(c) void
(d) args
(e) main
(f) static

5. What will be the result of compiling and running the following program?
package blog;

public class Integers {
  public static void main(String[] args) {
    System.out.println(0x10 + 10 + 010);
  }
}
Select the one correct answer.
(a) The program will not compile because of errors in the expression 0x10 + 10 + 010.
(b) When run, the program will print 28.
(c) When run, the program will print 30.
(d) When run, the program will print 34.
(e) When run, the program will print 36.
(f) When run, the program will print 101010.

6. Which of these assignments are valid?
Select the four correct answers.
(a) short s = 12;
(b) long l = 012;
(c) int other = (int) true;
(d) float f = -123;
(e) double d = 0x12345678;

7. What is the result of running the following program?
package blog;

public class OperandOrder {
  public static void main(String[] args) {
    int i = 0;
    int[] a = {3, 6};
    a[i] = i = 9;
    System.out.println(i + " " + a[0] + " " + a[1]);
  }
}
Select the one correct answer.
(a) When run, the program throws an exception of type ArrayIndexOutOfBoundsException.
(b) When run, the program will print "9 9 6".
(c) When run, the program will print "9 0 6".
(d) When run, the program will print "9 3 6".
(e) When run, the program will print "9 3 9".

8.  Which of the following expressions evaluate to true?
Select the two correct answers.
(a) (false | true)
(b) (null != null)
(c) (4 <= 4)
(d) (!true)
(e) (true & false)

9. What will be the result of attempting to compile and run the following class?

package blog.scjp;

public class IfTest {
      public static void main(String[] args) {
            if (true)
                  if (false)
                        System.out.println("a");
                  else
                        System.out.println("b");
      }
}
Select the one correct answer.
(a) The code will fail to compile because the syntax of the if statement is incorrect.
(b) The code will fail to compile because the compiler will not be able to deter- mine which if statement the else clause belongs to.
(c) The code will compile correctly and display the letter a, when run.
(d) The code will compile correctly and display the letter b, when run.
(e) The code will compile correctly, but will not display any output.

10. What will be the result of attempting to compile and run the following code?

package blog.scjp;

public class DoWhile {
      public static void main(String[] args) {
            boolean b = false;
            int i = 1;
            do {
                  i++;
                  b = !b;
            } while (b);
            System.out.println(i);
      }
}
Select the one correct answer.
(a) The code will fail to compile because b is an invalid conditional expression for the do-while statement.
(b) The code will fail to compile because the assignment b = ! b is not allowed.
(c) The code will compile without error and will print 1, when run.
(d) The code will compile without error and will print 2, when run.
(e) The code will compile without error and will print 3, when run.



SET-3 is about to come


***********************  SOLUTIONS *********************
1.  (b) 
Explanation : In addValue method local variable i value is being increment by 2  will not impact main method i variable, Main method i value is only increment by 1 using ++ operator. so output will be 1.

2.  (a), (d), (f) is the correct answer.
Explanations : These type of method declaration is called variable length argument. there are certain rules about that like "If there is more then one parameter in the method signature, variable length argument must be last argument" so option (c) and (e) is not valid as per this rule. 

3.  (c)
Explanations : Option c has primitive int array that why it will print proxy class reference id not value.

 4.  (a), (c), (f) 
Explanations : Rest are Identifiers.

5.  (d)
Explanations : value 0x is the symbol of hexadecimal value so 0x10 will be 16 in decimal and number started with 0 will be octal number so 010 in decimal will be 8 so final value in decimal will be 16 + 10 + 8 will be 34

6.  (a), (b), (d), (e) 
Explanations : boolean value can not caste to int.

7.  (b)
Explanations : array a[i] will be assign value first then i value will be changed.

8.  (a) and (c)

9.  (d)

10.  (e)


**********************************


No comments:

Post a Comment