Eclipse Java

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Nive8989
N
Nive8989
Community Contributor
Quizzes Created: 1 | Total Attempts: 212
Questions: 30 | Attempts: 212

SettingsSettingsSettings
Eclipse Java - Quiz


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

    Correct Answer
    C. Prints: 2, true
    Explanation
    The code first calculates the remainder of y divided by x using the modulus operator (%), which is 2. Then it checks if y is equal to the result of ((y/x) * x + (y%x)), which simplifies to ((5/3) * 3 + 2), which further simplifies to (1 * 3 + 2), which equals 5. Since y is indeed equal to 5, the expression evaluates to true. Therefore, the output will be "2, true".

    Rate this question:

  • 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

    Correct Answer
    D. Prints: A
    Explanation
    The program creates an instance of class A, passing an instance of class B as a parameter to its constructor. Class A extends Thread and overrides the run() method to print "A". Therefore, when the new A object is started, it will execute the run() method and print "A" as the output.

    Rate this question:

  • 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

    Correct Answer
    C. Planet Welcome
    Explanation
    The valid output for the given code will be "Planet Welcome". This is because the code is creating an instance of the class Code17 in the main method. Before the main method, there are two initialization blocks that print "Planet" and "Welcome" respectively. When the instance is created, these initialization blocks are executed in the order they appear, resulting in the output "Planet Welcome".

    Rate this question:

  • 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");

    Correct Answer(s)
    A. Float f = new Float("45.67d");
    C. Byte bite = new Byte("-128");
    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.

    Correct Answer(s)
    A. Annotations are not part of a program.
    D. Annotations are data about program.
    Explanation
    Annotations are not part of a program because they are metadata that provide additional information about the program but do not affect the program's execution. They can be used to add descriptive data or instructions to the program. Annotations are data about the program because they can be used to store information about the program's structure, behavior, or usage. This data can be accessed at runtime using reflection or used by other tools for code analysis or generation.

    Rate this question:

  • 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

    Correct Answer
    D. 'Before start method' only
    Explanation
    The correct answer is 'Before start method' only. This is because the stop() method is called immediately after the start() method, which causes the thread to stop before it even starts executing the run() method. Therefore, the only output that will be printed is 'Before start method'.

    Rate this question:

  • 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()

    Correct Answer(s)
    A. Equals(Object)
    B. HashCode()
    C. ToString()
    Explanation
    The methods equals(Object), hashCode(), and toString() are defined in the Object class. The equals(Object) method is used to compare two objects for equality, the hashCode() method returns the hash code value for an object, and the toString() method returns a string representation of an object. These three methods are fundamental methods in Java and are inherited by all classes in the Java language.

    Rate this question:

  • 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

    Correct Answer
    B. HelloolleH55
    Explanation
    The output of the code snippet will be "HelloolleH55". This is because the code first creates a StringBuffer object "sb" and reverses it using the reverse() method. Then, it concatenates the reversed "sb" with the original string "s1" using the concat() method. However, the result of the concatenation is not stored in any variable. Finally, it prints the concatenation of "s1" and "sb", followed by the lengths of both strings. Since "s1" is still "Hello" and "sb" is reversed to "olleH", the output is "HelloolleH55".

    Rate this question:

  • 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

    Correct Answer
    A. True
    Explanation
    Both TYPE_SCROLL_SENSITIVE and TYPE_SCROLL_INSENSITIVE ResultSets will make changes visible if they are closed and then reopened. This means that any changes made to the underlying data source will be reflected in the ResultSet when it is closed and then reopened. Therefore, the statement "True" is correct.

    Rate this question:

  • 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

    Correct Answer
    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
    Explanation
    The code snippet uses BufferedReader to read input from the keyboard line by line using the readLine() method. It then uses BufferedWriter to write the input to the console using the write() method. The code also flushes the output using the flush() method. Therefore, the code reads the text from the keyboard line by line and prints the same to the console on pressing the ENTER key at the end of every line.

    Rate this question:

  • 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

    Correct Answer(s)
    B. Public void eatMe() throws BadTasteException
    C. Public void eatMe() throws RuntimeException
    D. Public void eatMe() throws BitterException, SourException
    Explanation
    The compiler will accept the method declarations that correctly handle the exceptions that may be thrown by the eatMe method.
    - The declaration "public void eatMe() throws BadTasteException" is acceptable because it correctly handles the exception of type BadTasteException that may be thrown by the method.
    - The declaration "public void eatMe() throws RuntimeException" is acceptable because RuntimeException is an unchecked exception and does not need to be declared in the method signature.
    - The declaration "public void eatMe() throws BitterException, SourException" is acceptable because it correctly handles the exceptions of type BitterException and SourException that may be thrown by the method.

    Rate this question:

  • 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.

    Correct Answer
    D. Gamma has-a Beta and Gamma is-a Alpha
  • 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

    Correct Answer(s)
    B. Labeled continue
    E. Labeled break
    Explanation
    Java supports the flow control features of labeled continue and labeled break. Labeled continue allows the program to skip the current iteration of a labeled loop and move to the next iteration. Labeled break allows the program to exit a labeled loop or switch statement. These features provide flexibility and control over the flow of execution in Java programs.

    Rate this question:

  • 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

    Correct Answer
    C. B
    Explanation
    The output of the code snippet will be "Object". This is because the code creates an anonymous class that extends class B, and overrides the getMe() method. When the getMe() method is called on the object "a", it returns the reference to the anonymous class object. However, when we use getClass().getSuperclass().getName(), it returns the superclass of the object, which is class A. Finally, getName() returns the name of the class, which is "Object" for the superclass.

    Rate this question:

  • 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

    Correct Answer(s)
    B. An object is a collection of properties and methods
    C. A package is a collection of classes
    Explanation
    The correct answer is that an object is a collection of properties and methods and a package is a collection of classes. In object-oriented programming, an object is an instance of a class that encapsulates data (properties) and behavior (methods). A package, on the other hand, is a way to organize and group related classes together. Therefore, it is true that a package is a collection of classes.

    Rate this question:

  • 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

    Correct Answer(s)
    A. In an inheritance hierarchy, a superclass can also act as a sub class
    C. In an inheritance hierarchy, a subclass can also act as a super class
    E. Inheritance enables adding new features and functionality to an existing class without modifying the existing class
    Explanation
    Inheritance allows for the creation of a hierarchy where a superclass can also act as a subclass, meaning that it can inherit properties and methods from a higher-level class. Similarly, a subclass can also act as a superclass, meaning that it can have its own subclasses that inherit from it. This enables the sharing of data and methods among multiple classes, contradicting the statement that inheritance does not allow sharing. Additionally, inheritance allows for the addition of new features and functionality to an existing class without modifying the existing class, making it a powerful tool for extending and enhancing code.

    Rate this question:

  • 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

    Correct Answer
    B. ResultSet.TYPE_FORWARD_ONLY
    Explanation
    The default Scroll type for a ResultSet object is ResultSet.TYPE_FORWARD_ONLY. This means that the ResultSet can only be traversed in a forward direction and does not support scrolling or moving backwards.

    Rate this question:

  • 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

    Correct Answer
    C. Compilation Error
    Explanation
    The code will result in a compilation error because there are duplicate case labels in the switch statement. The case label "10" appears twice, which is not allowed in Java. Each case label in a switch statement must be unique.

    Rate this question:

  • 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"

    Correct Answer
    D. Prints: "Value of z: 15"
    Explanation
    The code segment starts with initializing the variable z to 8. Then, the expression "z += --z" is evaluated. The "--z" decrements the value of z by 1, resulting in z becoming 7. The "+=" operator adds the value of z (7) to the current value of z (7), resulting in z becoming 14. Finally, the value of z (14) is printed as part of the output statement "Value of z: 14". Therefore, the valid output for the code segment is "Value of z: 14".

    Rate this question:

  • 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

    Correct Answer(s)
    B. String s = new String("");
    C. String can be constructed from byte arrays
    E. String can be made from character arrays
    Explanation
    The correct answer choices demonstrate three different ways of constructing a String object. First, creating a String using an empty string literal: String s = new String("");. Second, constructing a String from byte arrays: String can be constructed from byte arrays. Lastly, creating a String from character arrays: String can be made from character arrays.

    Rate this question:

  • 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

    Correct Answer
    B. "abc"
    Explanation
    The code snippet concatenates the string "abc" with double quotes at the beginning and end. The backslash before each double quote is an escape character that allows the double quote to be included in the string. Therefore, the output of the code snippet will be "abc".

    Rate this question:

  • 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

    Correct Answer(s)
    A. @Deprecated
    C. @SuppressWarnings
    D. @Override
    Explanation
    The annotations @Deprecated, @SuppressWarnings, and @Override are not defined in the java.lang.annotation package. These annotations are part of the java.lang package, but not specifically defined in the java.lang.annotation package.

    Rate this question:

  • 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.

    Correct Answer
    A. Calling the wait method on an object.
    Explanation
    Calling the wait method on an object can cause a Thread to become non-runnable. The wait method is used to make a thread wait until another thread notifies it to resume. When a thread calls the wait method, it releases the lock on the object it is synchronized on and enters a waiting state. This means that the thread cannot continue its execution until it is notified by another thread. Therefore, calling the wait method on an object can cause a thread to become non-runnable.

    Rate this question:

  • 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

    Correct Answer(s)
    B. A constructor can be declared as private
    D. A constructor can access the non-static member of a class
    Explanation
    A constructor can be declared as private means that a class can have a private constructor, which can only be accessed within the class itself. This is often used to restrict the creation of objects of that class to specific methods or within the class itself.

    A constructor can access the non-static member of a class means that a constructor can access and initialize the non-static variables or members of a class. This allows the constructor to set initial values for the variables when an object is created.

    Rate this question:

  • 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

    Correct Answer(s)
    B. X[24] is 0
    E. X.length is 25
    Explanation
    The given line of code initializes an array of integers called "x" with a size of 25. In Java, when an array of integers is created, all elements are automatically initialized to their default value, which is 0 for integers. Therefore, x[24] is 0. Additionally, the length property of an array in Java returns the number of elements in the array, so x.length is 25. The other statements are incorrect.

    Rate this question:

  • 26. 

    Which of the following are methods static members of the Thread class? (Choose all that apply)

    • A.

      Start

    • B.

      Sleep

    • C.

      Run

    • D.

      Wait

    • E.

      Yield

    Correct Answer(s)
    B. Sleep
    E. Yield
    Explanation
    The correct answer is sleep and yield. The sleep method is a static method in the Thread class that allows a thread to pause for a specified amount of time. The yield method is also a static method in the Thread class that allows a thread to voluntarily give up its current time slice and allow other threads to execute. The start, run, and wait methods are not static methods in the Thread class.

    Rate this question:

  • 27. 

    A)Entries are not organised in key/value pairs.       b)Duplicate entries are rejected        Which interface of the java.util package offers the above specified behaviour?

    • A.

      List

    • B.

      Set

    • C.

      None of the listed options

    • D.

      Map

    Correct Answer
    B. Set
    Explanation
    The correct answer is Set. The Set interface in the java.util package does not organize entries in key/value pairs and it rejects duplicate entries. This means that each element in a Set must be unique and there is no specific order maintained for the elements.

    Rate this question:

  • 28. 

    Which of these belong to the set of Java keywords?

    • A.

      Statement

    • B.

      Validate

    • C.

      Assertion

    • D.

      Exception

    • E.

      None of the listed options

    Correct Answer
    E. None of the listed options
    Explanation
    None of the listed options belong to the set of Java keywords. Java keywords are predefined reserved words that have specific meanings and cannot be used as identifiers or variable names. The given options "statement", "validate", "assertion", and "exception" are not Java keywords.

    Rate this question:

  • 29. 

    Consider the following code snippet:  class Sample{  public static void main(String[] args){                    for(int i=0;i<5;i++){  switch(i)     case 0: System.out.println("v");break;     case 0: System.out.println("w");     case 0: System.out.println("x");break;     case 0: System.out.println("y");                       case 0: System.out.println("z");break;     case 0: System.out.println("d");                  }}}} What is the result of attempting to compile and run the program?

    • A.

      Prints: v w x y z

    • B.

      Prints: v w w x y y z d

    • C.

      Prints: v w x x y z z

    • D.

      Prints: d d d d d d

    • E.

      Prints: v w x y z d

    Correct Answer
    C. Prints: v w x x y z z
    Explanation
    The correct answer is "Prints: v w x x y z z". The code snippet contains a switch statement with multiple cases labeled as 0. Since all the cases have the same label, the code execution will fall through each case until it reaches a break statement. Therefore, when the variable i is 0, the code will print "v", "w", "x", and "z" because there are no break statements after these cases. As a result, the program will print "v w x x y z z".

    Rate this question:

  • 30. 

    Which of the following lines will compile without warning or error?

    • A.

      Float f=1.3;

    • B.

      Char c="a";

    • C.

      Byte b=257;

    • D.

      Boolean b=null;

    • E.

      Int i=10;

    Correct Answer
    E. Int i=10;
    Explanation
    The line "int i=10;" will compile without warning or error because it is assigning a valid integer value (10) to the integer variable "i".

    Rate this question:

Quiz Review Timeline +

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

  • Current Version
  • Jul 12, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Dec 19, 2011
    Quiz Created by
    Nive8989
Back to Top Back to top
Advertisement