Sail E0 Webinar

MCQs

Total Questions : 51 | Page 2 of 6 pages
Question 11.

Which of these packages contain classes and interfaces used for input & output operations 

of a program?


  1.    java.util
  2.    java.lang
  3.    java.io
  4.    All of the mentioned
 Discuss Question
Answer: Option C. -> java.io

java.io provides support for input and output operations.


Question 12.


What is the output of this program?


class output {
public static void main(String args[])
{
char c[]={'a','1','b',' ','A','0'];
for (int i = 0; i < 5; ++i) {
if(Character.isDigit(c[i]))
System.out.println(c[i]" is a digit");
if(Character.isWhitespace(c[i]))
System.out.println(c[i]" is a Whitespace character");
if(Character.isUpperCase(c[i]))
System.out.println(c[i]" is an Upper case Letter");
if(Character.isUpperCase(c[i]))
System.out.println(c[i]" is a lower case Letter");
i = i + 3;
}
}
}


a) a is a lower case Letter



is White space character



b) b is a lower case Letter



is White space characte



c) a is a lower case Letter



A is a upper case Letter



d) a is a lower case Letter



0 is a digit


  1.    java.util
  2.    java.lang
  3.    java.io
  4.    All of the mentioned
 Discuss Question
Answer: Option C. -> java.io

Answer: Option AExplanation: 
Question 13.


What is the output of this program?


import java.io.*;
class Chararrayinput {
public static void main(String[] args) {
String obj = "abcdefgh";
int length = obj.length();
char c[] = new char[length];
obj.getChars(0, length, c, 0);
CharArrayReader input1 = new CharArrayReader(c);
CharArrayReader input2 = new CharArrayReader(c, 1, 4);
int i;
int j;
try {
while((i = input1.read()) == (j = input2.read())) {
System.out.print((char)i);
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}
  1.    abc
  2.    abcd
  3.    abcde
  4.    None of the mentioned
 Discuss Question
Answer: Option D. -> None of the mentioned

No output is printed. CharArrayReader object input1 contains string "abcdefgh" whereas

object input2 contains string "bcde", when while((i=input1.read())==(j=input2.read())) is 

executed the starting character of each object is compared since they are unequal 

control comes out of loop and nothing is printed on the screen.

Output:
$ javac Chararrayinput.java
$ java Chararrayinput


Question 14.


What is the output of this program?


import java.io.*;
class Chararrayinput {
public static void main(String[] args) {
String obj = "abcdefgh";
int length = obj.length();
char c[] = new char[length];
obj.getChars(0, length, c, 0);
CharArrayReader input1 = new CharArrayReader(c);
CharArrayReader input2 = new CharArrayReader(c, 1, 4);
int i;
int j;
try {
while ((i = input1.read()) == (j = input2.read())) {
System.out.print((char)i);
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
  1.    abc
  2.    abcd
  3.    abcde
  4.    None of the mentioned
 Discuss Question
Answer: Option D. -> None of the mentioned

No output is printed. CharArrayReader object input1 contains string “abcdefgh” whereas object 

input2 contains string “bcde”, when while((i=input1.read())==(j=input2.read())) is executed the 

starting character of each object is compared since they are unequal control comes out of loop 

and nothing is printed on the screen.


Question 15.


What is the output of this program?


import java.io.*;
class Chararrayinput {
public static void main(String[] args) {
String obj = "abcdef";
int length = obj.length();
char c[] = new char[length];
obj.getChars(0, length, c, 0);
CharArrayReader input1 = new CharArrayReader(c);
CharArrayReader input2 = new CharArrayReader(c, 0, 3);
int i;
try {
while((i = input2.read()) != -1) {
System.out.print((char)i);
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}
  1.    abc
  2.    abcd
  3.    abcde
  4.    abcdef
 Discuss Question
Answer: Option A. -> abc

None.
Output:
$ javac Chararrayinput.java
$ java Chararrayinput
abc


Question 16.


What is the output of this program?


class output {
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello World");
s1.insert(6 , "Good ");
System.out.println(s1);
}
}
  1.    HelloGoodWorld
  2.    HellGoodoWorld
  3.    HellGood oWorld
  4.    Hello Good World
 Discuss Question
Answer: Option D. -> Hello Good World

The insert() method inserts one string into another. It is overloaded to accept values of all 

simple types, plus String and Objects. Sting is inserted into invoking object at specified 

position. "Good " is inserted in "Hello World" T index 6 giving "Hello Good World".

output:
$ javac output.java
$ java output
Hello Good World


Question 17.


What is the output of this program if input given is "abc'def/'egh"?


class Input_Output {
public static void main(String args[]) throws IOException {
char c;
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
do {
c = (char) obj.read();
System.out.print(c);
} while(c != '\'');
}
}
  1.    abc'
  2.    abcdef/'
  3.    abc'def/'egh
  4.    abcqfghq
 Discuss Question
Answer: Option A. -> abc'

`setminus`' is used for single quotes that is for representing ' .
Output:
$ javac Input_Output.java
$ java Input_Output
abc'



Question 18.


What is the output of this program?


class output {
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello");
s1.setCharAt(1,x);
System.out.println(s1);
}
}
  1.    xello
  2.    xxxxx
  3.    Hxllo
  4.    Hexlo
 Discuss Question
Answer: Option C. -> Hxllo

None.
Output:
$ javac output.java
$ java output
Hxllo


Question 19.


What is the output of this program?


import java.io.*;
class Chararrayinput {
public static void main(String[] args) {
String obj = "abcdef";
int length = obj.length();
char c[] = new char[length];
obj.getChars(0, length, c, 0);
CharArrayReader input1 = new CharArrayReader(c);
CharArrayReader input2 = new CharArrayReader(c, 0, 3);
int i;
try {
while ((i = input2.read()) != -1) {
System.out.print((char)i);
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
  1.    abc
  2.    abcd
  3.    abcde
  4.    abcdef
 Discuss Question
Answer: Option A. -> abc


Question 20.


What is the output of this program?


class output {
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello");
StringBuffer s2 = s1.reverse();
System.out.println(s2);
}
}
  1.    Hello
  2.    olleH
  3.    HelloolleH
  4.    olleHHello
 Discuss Question
Answer: Option B. -> olleH

reverse() method reverses all characters. It returns the reversed object on which it was called.
Output:
$ javac output.java
$ java output
olleH


Latest Videos

Latest Test Papers