Input/Output in Java

Input/Output in Java

15 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following symbols is used for representing the XOR operator in Java?

  1. ~
  2. &
  3. |
  4. ^
Question 2 Multiple Choice (Single Answer)

How many string objects are created by the given statement?
String str=new String(“Aliens”);

  1. 0
  2. 1
  3. 2
  4. 4
Question 3 Multiple Choice (Single Answer)

What will be the value of “str” after executing the following statements?
StringBuffer str=new StringBuffer(“I am a student”);
str.delete(2,6);

  1. I student
  2. Istudent
  3. Itudent
  4. I am a student
Question 4 Multiple Choice (Single Answer)

Which of the following statements is/are correct?
A. The size of a vector can grow or shrink.
B. The size of an array can grow or shrink.

  1. Only A
  2. Only B
  3. Both A and B
  4. Neither A nor B
Question 5 Multiple Choice (Single Answer)

What is the size and capacity of the Vector Num in the following code?
Vector Num=new Vector(10)

  1. Size = 10, capacity = 0
  2. Size = 0, capacity = 10
  3. Size = 10, capacity = 10
  4. Size = 0, capacity = 0
Question 6 Multiple Choice (Single Answer)

The method readLine() can be accessed by the object of a ____________ class to read a string from console.

  1. InputStreamReader
  2. InputStream
  3. BufferedReader
  4. StringReader
Question 7 Multiple Choice (Single Answer)

What is the correct syntax of replace() method of the StringBuffer class?

  1. StringBuffer replace(int s,int e)
  2. StringBuffer replace(int s,String str)
  3. StringBuffer replace(int s,String str1,String str2)
  4. StringBuffer replace(int s,int e,String str)
Question 8 Multiple Choice (Single Answer)

The methods of NumberFormat class are used to display the numbers in standard formats(Currency values and percentage values).The NumberFormat class belongs to which of the following packages?

  1. java.lang
  2. java.io
  3. java.text
  4. java.txt
Question 9 Multiple Choice (Single Answer)

Which of the following statement(s) is/are correct?
A. valueOf() is a static method.
B. toString() is overridden in Integer and Double Class.

  1. Only A
  2. Only B
  3. Both A and B
  4. Neither A nor B
Question 10 Multiple Choice (Single Answer)

The constructor StringBuffer() of a StringBuffer class creates a string buffer with the capacity of ________ characters by default.

  1. 8
  2. 16
  3. 32
  4. 64
Question 11 Multiple Choice (Single Answer)

The class String is defined in the package ___________.

  1. java.awt
  2. java.lang
  3. java.math
  4. java.net
Question 12 Multiple Choice (Single Answer)

Java does not support ____________.

  1. arrays
  2. multithreading
  3. pointers
  4. constructors
Question 13 Multiple Choice (Single Answer)

Which of the following methods of a String class is used to compare the given string “str1” to another string “str2” by ignoring the case consideration?

  1. str1.equals(str2);
  2. str1.equalsIgnoreCase(str2)
  3. str1.equalignoreCase(str2)
  4. str1.equalsIgnorecase(str2)
Question 14 Multiple Choice (Single Answer)

Which of the following methods is used to get the index within the given string “str” at the first occurrence of the specified substring “str1”?

  1. str1.indexOf(int ch,int from Index)
  2. str1.indexOf(String str)
  3. str.indexOf(string str1)
  4. str.indexOf(String str1)
Question 15 Multiple Choice (Single Answer)

Which of the following is not a valid statement in Java?

  1. str1.equalsIgnoreCase(str2)
  2. str1.equalsIgnoreCase()
  3. “Hello”.equalsIgnoreCase(“hello”)
  4. str1.equals(str2)