EnsurepassQUESTION 121 Given:     What is the result?   A. The program prints nothing B. d C. A StringIndexOutOfBoundsException is thrown at runtime. D. AnArrayIndexOutOfBoundsException is thrown at runtime. E. A NullPointerException is thrown at runtime.   Correct Answer: C     QUESTION 122 Given the code fragment:     What is the result?   A. 10 8 6 4 2 0 B. 10 8 6 4 2 C. AnArithmeticException is thrown at runtime D. Read more [...]
EnsurepassQUESTION 141 Given:   public class String1 {   public static void main(String[] args) {   String s = "123";   if (s.length() >2)   s.concat("456");   for(int x = 0; x <3; x++)   s += "x"; System.out.println(s);   }   }   What is the result?   A. 123 B. 123xxx C. 123456 D. 123456xxx E. Compilation fails   Correct Answer: B Explanation: 123xxx The if clause is not applied.   Note: Syntax of if-statement: Read more [...]
EnsurepassQUESTION 91 Which two are Java Exception classes?   A. SercurityException B. DuplicatePathException C. IllegalArgumentException D. TooManyArgumentsException   Correct Answer: AC     QUESTION 92 Given the code fragment:     What is the result?   A. A B C B. A B C D E C. A B D E D. Compilation fails.   Correct Answer: C     ;             QUESTION 93 Given:   public class FieldInit Read more [...]
EnsurepassQUESTION 131 Given:   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();   Correct Answer: ADE Explanation: Incorrect: Not B, not C: Pet is abstact, cannot be instantiated. Not F: incompatible type. Required Beagle, found Dog.     Read more [...]
EnsurepassQUESTION 111 Given:     Which option enables the code to compile?     A. Option A B. Option B C. Option C D. Option D   Correct Answer: CD     QUESTION 112 Given the code fragment:     Which modification enables the code to print 54321?   A. Replace line 6 with System, out. print (--x) ; B. At line 7, insert x --; C. Replace line 6 with --x; and, at line 7, insert system, out. print (x); D. Replace line 12 Read more [...]
EnsurepassQUESTION 81 Given the code fragment:     Which code fragment prints red: blue: small: medium?     A. Option A B. Option B C. Option C D. Option D   Correct Answer: D           QUESTION 82 Given:     What is the result?   A. true:true B. true:false C. false:true D. false:false   Correct Answer: C     QUESTION 83 Given:     What is the result?   A. 6 7 8 B. Read more [...]
EnsurepassQUESTION 41 You are asked to develop a program for a shopping application, and you are given the following information:   The application must contain the classes Toy, EduToy, and consToy. The Toy class is the superclass of the other two classes. The int caicuiatePrice (Toy t) method calculates the price of a toy. The void printToy (Toy t) method prints the details of a toy.   Which definition of the Toy class adds a valid layer of abstraction to the class hierarchy?     Read more [...]
EnsurepassQUESTION 101 Given:   public class TestField {   int x;   int y;   public void doStuff(int x, int y) {   this.x = x;   y =this.y;   }   public void display() {   System.out.print(x + " " + y + " : ");   }   public static void main(String[] args) {   TestField m1 = new TestField();   m1.x = 100;   m1.y = 200;   TestField m2 = new TestField();   m2.doStuff(m1.x, m1.y);   m1.display();   m2.display(); Read more [...]
EnsurepassQUESTION 71 Given the following four Java file definitions:   // Foo.java   package facades;   public interface Foo { }   // Boo.java   package facades;   public interface Boo extends Foo { }   // Woofy.java   package org.domain   // line n1 public class Woofy implements Boo, Foo { }   // Test.java   package.org;   public class Test {   public static void main(String[] args) {   Foo obj=new Woofy();   Which set modifications Read more [...]
EnsurepassQUESTION 31 Which of the following can fill in the blank in this code to make it compile?     A. abstract B. public C. default D. It will not compile with any as interfaces cannot have non abstract methods. E. It will compile without filling the blank.   Correct Answer: C Explanation: From Java SE 8, we can use static and/or default methods in interfaces, but they should be non abstract methods. SO in this case using default in blank is completely legal. Read more [...]
EnsurepassQUESTION 61 Which two statements are true for a two-dimensional array of primitive data type?   A. It cannot contain elements of different types. B. The length of each dimension must be the same. C. At the declaration time, the number of elements of the array in each dimension must be specified. D. All methods of the class object may be invoked on the two-dimensional array.   Correct Answer: CD Explanation: http://stackoverflow.com/questions/12806739/is-an-array-a-primitive-type-or-an-object-or-something-else-entirely Read more [...]
EnsurepassQUESTION 51 Given:   class MarksOutOfBoundsException extends IndexOutOfBoundsException { }   public class GradingProcess {   void verify(int marks) throws IndexOutOfBoundsException {   if (marks > 100) {   throw new MarksOutOfBoundsException();   }   if (marks > 50) {   System.out.print("Pass");   } else {   System.out.print("Fail");   }   }   public static void main(String[] args) { int marks = Integer.parseInt(args[2]); Read more [...]
EnsurepassQUESTION 21 Given the code fragment:     What is the result?   A. Execution terminates in the first catch statement, and caught a RuntimeException is printed to the console. B. Execution terminates In the second catch statement, and caught an Exception is printed to the console. C. A runtime error is thrown in the thread "main". D. Execution completes normally, and Ready to us?is printed to the console. E. The code fails to compile because a throws keyword Read more [...]
EnsurepassQUESTION 11 Given:     Which of the following is equivalent to the above code fragment?   A. System.out.printLn(x>10?">,': "<":,'="); B. System.out.println(x>10? ">"?"<":"="); C. System.out.println(x>10?">":x<10?"<":"="); D. System.out.printLn(x>10?">"?,'<"?"="); E. None of the above   Correct Answer: B Explanation: Option A is incorrect as we can't use abstract with non abstract method, (here method has method Read more [...]
EnsurepassQUESTION 1 Given:     What is the result?   A. hEllOjAvA! B. Hello java! C. Out of limits hEllOjAvA! D. Out of limits   Correct Answer: C     QUESTION 2 Given the code fragment:     Which code fragment, when inserted at line 3, enables the code to print 10:20?   A. int[] array n= new int[2]; B. int[] array; array = int[2]; C. int array = new int[2]; D. int array [2] ;   Correct Answer: A       QUESTION 3 Given:     What Read more [...]