Choose Correct Answer Core Java

25 Questions | Total Attempts: 596

SettingsSettingsSettings
Please wait...
Core Java Quizzes & Trivia

Pls do the correction if the answer is wrong in core java.


Questions and Answers
  • 1. 
    Which of the following may override a method whose signature is void xyz (float f)?1.void xyz(float f)2.public void xyz(float f3,private void xyz(float f)
    • A. 

      1, 2

    • B. 

      2, 3

    • C. 

      3

    • D. 

      1,3

  • 2. 
    2, 31 An anonymous inner class may implement at most one interface.2 An anonymous inner class may implement arbitrarily many interfaces.3 An anonymous inner class may extend a parent class other than Object.
    • A. 

      2, 3

    • B. 

      1,3

    • C. 

      3

    • D. 

      1,2

  • 3. 
    Which of the following are valid declarations? 1 int $x; 2 int 123; 3 int _123;
    • A. 

      1,2

    • B. 

      2,3

    • C. 

      1,3

    • D. 

      None of the above

  • 4. 
    Which line if inserted independently at line 6, will compile in the code given below? 1. class Voop {2. public static void main(String[] args) {3. doStuff(1);4. doStuff(1,2);5. }6. // insert code here7. } 1. static void doStuff(int... doArgs) { } 2. static void doStuff(int[] doArgs) { }3. static void doStuff(int x, int... doArgs) { }
    • A. 

      1,3

    • B. 

      2,3

    • C. 

      1,2,3

    • D. 

      None of the above

  • 5. 
    What value does readLine() return when it has reached the end of the file?
    • A. 

      1

    • B. 

      -1

    • C. 

      Null

    • D. 

      0

  • 6. 
    Which of the following statements are true? 1 The invocation of an object’s finalize () method is always the last thing that happens before an object is garbage collected (GCed). 2 When a stack variable goes out of scope, it is eligible for GC. 3 Some reference variables live on the stack, and some live on the heap.
    • A. 

      1

    • B. 

      2

    • C. 

      None of above

    • D. 

      3

  • 7. 
    Which of the following statements are true about reference variables? 1 A reference variable type can be changed. 2 A reference is a variable, so it can be reassigned to other objects (unless the reference is declared final). 3 A reference variable's type determines the methods that can be invoked on the object the variable is referencing.
    • A. 

      1,2

    • B. 

      3

    • C. 

      2,3

    • D. 

      1

  • 8. 
    Which of the following rules are applicable for overriding?1 The argument list must exactly match that of the overridden method. 2 The return type can be of any type. 3 The access level can be more restrictive than the overridden methods.
    • A. 

      1,2

    • B. 

      Which of the following rules are applicable for overriding? 1 The argument list must exactly match that of the overridden method. 2 The return type can be of any type. 3 The access level can be more restrictive than the overridden methods.

    • C. 

      2,3

    • D. 

      3

    • E. 

      1

  • 9. 
    Which of the following statements are not true about a constructor? 1 Can use any access modifier, including private. 2 The constructor name should match the name of the class. 3 Constructors must have a return type.
    • A. 

      2,3

    • B. 

      1

    • C. 

      1,2

    • D. 

      3

  • 10. 
    The _________ and _________ classes enable objects and values of primitive types to be written to and read from streams.
    • A. 

      ObjectOutputStream, ObjectInputStream

    • B. 

      PipedOutputStream, ObjectInputStream

    • C. 

      PipedInputStream, ObjectOutputStream

    • D. 

      PipedInputStream, PipedOutputStream

  • 11. 
    Which of the following are true about I/O filters?
    • A. 

      Filters are supported on input, but not on output.

    • B. 

      Filters read from one stream and write to another

    • C. 

      Filters are supported by the InputStream/OutputStream class hierarchy but not by the Reader/Writer class hierarchy.

    • D. 

      A filter may alter data that is read from one stream and written to another.

  • 12. 
    Which of the following is True about the three java.lang classes String, StringBuilder, and StringBuffer? 1. All three classes have a length () method.2. Objects of type StringBuffer are thread-safe.3. The value of an instance of any of these three types can be modified through various methods in the API.
    • A. 

      1

    • B. 

      3

    • C. 

      1,2

    • D. 

      2,3

  • 13. 
    Given a properly prepared String array containing five elements, what range of results could a proper invocation of Arrays.binarySearch () produce?
    • A. 

      0 through 4

    • B. 

      0 through 5

    • C. 

      6 through 4

    • D. 

      -6 through 5

  • 14. 
    Which of the following statements are true about a static nested class? 1 You must have a reference to an instance of the enclosing class in order to instantiate it. 2 It does not have access to non-static members of the enclosing class. 3 Its variables and methods must be static.
    • A. 

      2

    • B. 

      1

    • C. 

      3

    • D. 

      None of the above

  • 15. 
    Which of these classes defined in java.io and used for file-handling are abstract?
    • A. 

      PrintStream, InputStream

    • B. 

      FileInputStream, Reader

    • C. 

      FileWriter, InputStrea

    • D. 

      InputStream, Reader

  • 16. 
    Which of the following are true about the File class? 1) A file object can be used to change the current working directory. 2) A file object can be used to access the files in the current working directory. 3) When a file object is created, a corresponding directory or file is created in the local file system. 4) File objects are used to access files and directories on the local file system. 5) File objects can be garbage collected.
    • A. 

      1,3,5

    • B. 

      2,4,5

    • C. 

      2,3,4

    • D. 

      1,2,3

  • 17. 
    Which method of the CharArrayWriter class copies and converts the output buffer to a String object?
    • A. 

      WriteTo()

    • B. 

      Size()

    • C. 

      ToString()

    • D. 

      Reset()

  • 18. 
    Which of the following are methods of InputStream class? 1) read() 2) available() 3) close() 4) flush()5) write()
    • A. 

      1,3,5

    • B. 

      2,4,5

    • C. 

      1,2,3

    • D. 

      3,4,5

  • 19. 
    You need to read in the lines of a large text file containing tens of megabytes of data. Which of the following would be most suitable for reading in such a file?
    • A. 

      New BufferedReader(new InputStreamReader(new FileInputStream("file.name");

    • B. 

      New FileInputStream("file.name")

    • C. 

      New InputStreamReader(new FileInputStream("file.name")

    • D. 

      New RandomAccessFile raf = new RandomAccessFile("myfile.txt","+rw");

  • 20. 
    Which of the following statements are true? 1 The notifyAll () method must be called from a synchronized context. 2 To call wait (), an object must own the lock on the thread. 3 The notify () method is defined in class java.lang.Thread.
    • A. 

      2

    • B. 

      None of the above

    • C. 

      3

    • D. 

      1

  • 21. 
    What is the result of code given below?public static synchronized void main(String[] args) throwsInterruptedException {Thread t = new Thread();t.start();System.out.print("X");t.wait(10000);System.out.print("Y");}
    • A. 

      It prints X and exits.

    • B. 

      It prints X and never exits.

    • C. 

      An exception is thrown at runtime.

    • D. 

      It prints XY and exits almost immediately

  • 22. 
    Consider the following line of code: int []x=new int[25]; After execution, which of the following are true? 1 x[24] is 0 2 x[24] is undefined 3 x[25] is 0
    • A. 

      2

    • B. 

      None of the above

    • C. 

      3

    • D. 

      1

  • 23. 
    After execution of the following code fragment, what are the values of the variables x, a and b? int x, a=6,b=7;x=a++ + b++;
    • A. 

      Fsdfsd

    • B. 

      Asd

  • 24. 
    Which of the following may appear on the left-hand side of an instanceOf operator? 1. a reference 2. a class 3. an interface4. a variable of primitive type
    • A. 

      1,2

    • B. 

      1,3

    • C. 

      1.4

    • D. 

      2,3

  • 25. 
    Consider the following class definitions: Which of the following are legitimate calls to construct instances of the Test class? public class Test extends Base{ public Test(int j){}public Test(int j, int k){super(j,k);}} 1. Test t = new Test(); 2. Test t = new Test(1); 3. Test t = new Test(1,2);
    • A. 

      1,2

    • B. 

      2,3

    • C. 

      3

    • D. 

      1,3

Back to Top Back to top