Eclipse Java

30 Questions | Total Attempts: 135

SettingsSettingsSettings
Please wait...
The Eclipse Quizzes & Trivia

Eclipse JAVA


Questions and Answers
  • 1. 
    Consider the following code: public class TestOne {    public static void main(String args[])      {        byte x = 3;         byte y = 5;         System.out.print((y%x) + ", "); System.out.println(y == ((y/x) *x +(y%x))); } } Which of the following gives the valid output for above?
    • A. 

      Prints 2, false

    • B. 

      Prints: 1, true

    • C. 

      Prints: 2, true

    • D. 

      Prints: 1, true

  • 2. 
    Consider the following program:   class A extends Thread {    public A(Runnable r) {}    public void run() {    System.out.print("A");    } }  class B implements Runnable {    public void run(){    System.out.print("B");    } }  class C{    public static void main(String[] args) {    new A(new B()).start();    } }  What will be the output of the above program?
    • A. 

      Compile-time error

    • B. 

      Prints: AB

    • C. 

      Prints: BA

    • D. 

      Prints: A

    • E. 

      Prints: B

  • 3. 
    Dd3)6)  Consider the following code:   public class Code17  {      public static void main(String args[]) {      new Code17();       }      { System.out.print("Planet "); }      { System.out.print("Welcome "); }      }      Which of the following will be the valid output for the above code?
    • A. 

      Compilation Error

    • B. 

      Planet

    • C. 

      Planet Welcome

    • D. 

      Welcome Planet

  • 4. 
    Which of the following are the valid ways of creating wrapper type objects? (Choose 3)
    • A. 

      Float f = new Float("45.67d");

    • B. 

      Character c = new Character("a");

    • C. 

      Byte bite = new Byte("-128");

    • D. 

      Integer integer = new Integer("false");

    • E. 

      Boolean b = new Boolean("23.9");

  • 5. 
    Which of the following are characteristics of Annotations?(Choose 2)
    • A. 

      Annotations are not part of a program.

    • B. 

      Annotations are static methods.

    • C. 

      Annotations are predefined classes.

    • D. 

      Annotations are data about program.

  • 6. 
    Consider the following program:                 public class D extends Thread { public void run() {                   System.out.println("Before start method");                    this.stop();                    System.out.println("After stop method");                    }                    public static void main(String[] args) {                      D a = new D(); a.start();                      } }        What will be the output of the above program?
    • A. 

      Compilation error

    • B. 

      'Before start method' and 'After stop method'

    • C. 

      Runtime exception

    • D. 

      'Before start method' only

  • 7. 
    Which of the following methods are defined in Object class? (Choose 3)
    • A. 

      Equals(Object)

    • B. 

      HashCode()

    • C. 

      ToString()

    • D. 

      CompareTo(Object)

    • E. 

      Run()

  • 8. 
    Consider the following code snippet:                class TestString3 {                   public static void main(String args[]) {                     String s1 = "Hello";                     StringBuffer sb = new StringBuffer(s1);                         sb.reverse();                         s1.concat(sb.toString());                         System.out.println(s1 + sb + s1.length() + sb.length());                  } }            What will be the output of the above code snippet?
    • A. 

      HelloolleH44

    • B. 

      HelloolleH55

    • C. 

      HelloHello55

    • D. 

      HelloHello33

    • E. 

      HelloHello44

  • 9. 
    Both TYPE_SCROLL_SENSITIVE and TYPE_SCROLL_INSENSITIVE types                 ResultSets will make changes visible if they are closed and then reopened.                 State True or False.
    • A. 

      True

    • B. 

      False

  • 10. 
    Consider the following code snippet:                 import java.io.*;                  public class IOCode1 {                      public static void main(String args[]) throws IOException {                            BufferedReader br1 = new BufferedReader( new InputStreamReader(System.in));                             BufferedWriter br2 = new BufferedWriter( new OutputStreamWriter(System.out));                             String line = null;                            while( (line = br1.readLine()) != null )                         {                             br2.write(line);                              br2.flush();                           }                                br1.close();                                 br2.close();                  } }                   What will be the output for the above code snippet?
    • A. 

      Reads the text from keyboard and prints the same to the console on pressing Ctrl Z, flushes (erases) the same from the console.

    • B. 

      Reads the text from keyboard line by line and prints the same to the console on pressing ENTER key at the end of every line, then the same is flushed (erased) from the console.

    • C. 

      Reads the text from keyboard and prints the same to the console on pressing Ctrl Z

    • D. 

      Reads the text from keyboard character by character and prints the same to the console on typing every character.

    • E. 

      Reads the text from keyboard line by line and prints the same to the console on pressing ENTER key at the end of every line

  • 11. 
    Consider the following scenario: You are writing a set of classes related to cooking and have created your own exception hierarchy derived from java.lang.Exception as follows: Exception     +-Bad TasteException     +-Bitter Exception     +-Sour Excpetion BadTasteException is defined as an abstract class. You have a method eatMe that may throw a BitterException or a SourException. Which of the following method declarations are acceptable to the compiler? (Choose 3)
    • A. 

      Public void eatMe() throws Throwable

    • B. 

      Public void eatMe() throws BadTasteException

    • C. 

      Public void eatMe() throws RuntimeException

    • D. 

      Public void eatMe() throws BitterException, SourException

    • E. 

      Public void eatMe() throw BadTasteException

  • 12. 
    Consider the following code:                 class Alpha {                    protected Beta b;                     }                 class Gamma extends Alpha { }                 class Beta { }          Which of the following statement is True?
    • A. 

      Alpha is-a Gamma and has-a Beta.

    • B. 

      Beta has-a Gamma and Gamma is-a Alpha.

    • C. 

      Alpha has-a Beta and Alpha is-a Gamma

    • D. 

      Gamma has-a Beta and Gamma is-a Alpha

    • E. 

      Alpha is-a Gamma and has-a Beta.

  • 13. 
    Which of the following flow control features does Java support? (Choose 2)
    • A. 

      Labeled goto

    • B. 

      Labeled continue

    • C. 

      Labeled throw

    • D. 

      Labeled catch

    • E. 

      Labeled break

  • 14. 
    Consider the following code:  class A {    public A getMe() {     return this;                    }  }  class B extends A {   public static void main(String args[]) {    A a = new B() {  public A getMe() {                     return this;  } };  System.out.println(a.getClass().getSuperclass().getName());   } }           Which of the following will be the output of the above code snippet?
    • A. 

      A

    • B. 

      Runtime error

    • C. 

      B

    • D. 

      Object

    • E. 

      Anonymous

  • 15. 
    Which of the following statements are true?(Choose 2)
    • A. 

      A class is a collection of objects

    • B. 

      An object is a collection of properties and methods

    • C. 

      A package is a collection of classes

    • D. 

      A package is a collection of objects

    • E. 

      An object is a collection of pacakges

  • 16. 
    Which of the following are true about inheritance?(Choose 3)
    • A. 

      In an inheritance hierarchy, a superclass can also act as a sub class

    • B. 

      Inheritance is a kind of Encapsulation

    • C. 

      In an inheritance hierarchy, a subclass can also act as a super class

    • D. 

      Inheritance does not allow sharing data and methods among multiple classes

    • E. 

      Inheritance enables adding new features and functionality to an existing class without modifying the existing class

  • 17. 
    What of the following is the default Scroll type for a ResultSet object?
    • A. 

      ResultSet.TYPE_SCROLLABLE

    • B. 

      ResultSet.TYPE_FORWARD_ONLY

    • C. 

      ResultSet.TYPE_SCROLL_SENSITIVE

    • D. 

      ResultSet.TYPE_SCROLL_BIDIRECTIONAL

  • 18. 
    Consider the following code:   public class SwitchCase {    public static void main(String args[]) {     int x = 10; switch(x) {     case 10: System.out.println("10");     case 10: System.out.println("10");     case 20: System.out.println("20");     default: System.out.println("30");  } } }       Which of the following will be the output for the above program?
    • A. 

      10 10

    • B. 

      10 10 20

    • C. 

      Compilation Error

    • D. 

      10 20

    • E. 

      30

  • 19. 
    Consider the following code segment:  public class ExampleTwo {    public static void main(String args[]) {    int z = 8;    z += --z;    System.out.println("Value of z : " + z);  }  }           Which of the following gives the valid output for above?
    • A. 

      Prints: "Value of z: 16"

    • B. 

      A runtime ArithmeticException will be thrown.

    • C. 

      Prints: "Value of z: 14"

    • D. 

      Prints: "Value of z: 15"

  • 20. 
    Which of the following exhibits the different ways of constructing a String object?(Choose 3)
    • A. 

      String s = new String[5];

    • B. 

      String s = new String("");

    • C. 

      String can be constructed from byte arrays

    • D. 

      String s = new String(null);

    • E. 

      String can be made from character arrays

  • 21. 
    Consider the following code snippet:  String a = "abc";  For the expression a="\""+a+"\""        What will be the output of the above code snippet?
    • A. 

      "a= abc"

    • B. 

      "abc"

    • C. 

      ""abc"" e. "abc"

    • D. 

      \"abc\"

    • E. 

      Abc

  • 22. 
    Which of the following annotations are NOT defined in java.lang.annotation package? (Choose 2)
    • A. 

      @Deprecated

    • B. 

      @Target

    • C. 

      @SuppressWarnings

    • D. 

      @Override

    • E. 

      @Retention

  • 23. 
    What can cause a Thread to become non-runnable?
    • A. 

      Calling the wait method on an object.

    • B. 

      Callling the notifyAll method on an object.

    • C. 

      Existing from a synchronized block.

    • D. 

      Calling the noitify method on an object.

  • 24. 
    Which of the statements are True?
    • A. 

      All classes must define a constructor

    • B. 

      A constructor can be declared as private

    • C. 

      A constructor can declare a value

    • D. 

      A constructor can access the non-static member of a class

  • 25. 
    Consider the following line of Code:         int x[]=new int[25];        After execution ,which of the following statement/ statements are true?
    • A. 

      X[25] is 0

    • B. 

      X[24] is 0

    • C. 

      X[0] is null

    • D. 

      X[24] is undefined

    • E. 

      X.length is 25

Back to Top Back to top