Explore topic-wise MCQs in Java Programming.

This section includes 22 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

What is the output of this program?import java.io.*; public class files_Example { public static void main(String args[]) { File object = new File("/new folder/system"); System.out.print(object.getName()); } }

A. new folder
B. new folder/system
C. /new folder/system
D. system
E. None of these
Answer» E. None of these
2.

What is the output of this program?import java.io.*; public class filesinputoutput_Example { public static void main(String args[]) { InputStream obj = new FileInputStream("inputoutput.java"); System.out.print(obj.available()); } }

A. Compilation error
B. Runtime error
C. true
D. false
E. None of these
Answer» B. Runtime error
3.

What is the output of this program?import java.io.*; public class filesinputoutput_Example { public static void main(String[] args) { String object = "interview mania"; byte p[] = object.getBytes(); ByteArrayInputStream object1 = new ByteArrayInputStream(p); for (int K = 0; K < 2; ++K) { int q; while ((q = object1.read()) != -1) { if (K == 0) { System.out.print(Character.toUpperCase((char)q)); } } } } }

A. interview mania
B. MANIA
C. INTERVIEW
D. INTERVIEW MANIA
E. None of these
Answer» E. None of these
4.

What is the output of this program?import java.io.*; public class filesinputoutput_Example { public static void main(String[] args) { String object = "interview Mania"; byte p[] = object.getBytes(); ByteArrayInputStream object1 = new ByteArrayInputStream(p); for (int K = 0; K < 2; ++K) { int q; while ((q = object1.read()) != -1) { if(K == 0) { System.out.print((char)q); } } } } }

A. interview
B. interview Mania
C. Maniainterview
D. interview Mania
E. None of these
Answer» E. None of these
5.

What is the output of this program?import java.io.*; public class Chararrayinput_Example { public static void main(String[] args) { String object = "pqrst"; int length = object.length(); char p[] = new char[length]; object.getChars(0, length, p, 0); CharArrayReader input1 = new CharArrayReader(p); CharArrayReader input2 = new CharArrayReader(p, 1, 4); int K; int L; try { while ((K = input1.read()) == (L = input2.read())) { System.out.print((char)K); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }

A. pqrst
B. pqr
C. rst
D. pqrs
E. None of these
Answer» F.
6.

What is the output of this program?import java.io.*; public class Chararrayinput_Example { public static void main(String[] args) { String object = "Interview Mania"; int length = object.length(); char p[] = new char[length]; object.getChars(0, length, p, 0); CharArrayReader input1 = new CharArrayReader(p); CharArrayReader input2 = new CharArrayReader(p, 0, 9); int K; try { while ((K = input2.read()) != -1) { System.out.print((char)K); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }

A. Interview Mania
B. Mania
C. Interview
D. ManiaInterview
E. None of these
Answer» D. ManiaInterview
7.

What is the output of this program if input given is InterviewMania ?import java.util.*;import java.io.*; public class IO_Example { public static void main(String args[]) throws IOException { char ch; BufferedReader obj = new BufferedReader(new InputStreamReader(System.in)); do { ch = (char) obj.read(); System.out.print(ch); } while(ch!='w'); } }

A. InterviewMania
B. Mania
C. Interview
D. ManiaInterview
E. None of these
Answer» D. ManiaInterview
8.

What is the output of this program?public class output { public static void main(String args[]) { StringBuffer c = new StringBuffer("InterviewMania"); System.out.println(c.length()); } }

A. 11
B. 12
C. 13
D. 14
E. 15
Answer» E. 15
9.

What is the output of this program if input given is prstquvwxyz ?import java.util.*;import java.io.*; public class Main { 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 != 'q'); } }

A. prstquvwxyz
B. prstquv
C. prstq
D. quvwxyz
E. None of these
Answer» D. quvwxyz
10.

What is the output of this program?public class IndexOf_Example { public static void main(String args[]) { String str="My first love is java."; System.out.println(str.indexOf('i')+" "+str.indexOf('o')+" "+str.lastIndexOf('i')+" "+str.lastIndexOf('j') ); } }

A. 10 14 17 4
B. 17 14 10 4
C. 4 10 14 17
D. 10 4 14 17
E. None of these
Answer» D. 10 4 14 17
11.

What is the output of this program?public class output { public static void main(String args[]) { StringBuffer s1 = new StringBuffer("Interview"); s1.setCharAt(8,'W'); System.out.println(s1); } }

A. Interview
B. Mania
C. Compilation Error
D. IntervieW
E. Runtime Error
Answer» E. Runtime Error
12.

What is the output of this program?import java.io.*; public class Chararrayinput_Example { public static void main(String[] args) { String object = "InterviewMania"; int len = object.length(); char array[] = new char[len]; object.getChars(0, len, array, 0); CharArrayReader chararray = new CharArrayReader(array); CharArrayReader chararray0 = new CharArrayReader(array, 1, 4); int K; int L; try { while((K = chararray.read()) == (L = chararray0.read())) { System.out.print((char)K); } } catch (IOException e) { e.printStackTrace(); } } }

A. Interview
B. InterviewMania
C. Mania
D. All of these
E. None of these
Answer» F.
13.

What is the output of this program?import java.io.*; public class Chararrayinput_Example { public static void main(String[] args) { String object = "InterviewMania"; int len = object.length(); char ch[] = new char[len]; object.getChars(0, len, ch, 0); CharArrayReader chararray = new CharArrayReader(ch); CharArrayReader chararray0 = new CharArrayReader(ch, 0, 9); int i; try { while((i = chararray0.read()) != -1) { System.out.print((char)i); } } catch (IOException e) { e.printStackTrace(); } } }

A. Interview
B. Mania
C. InterviwMania
D. Runtime Error
E. Compilation Error
Answer» B. Mania
14.

What is the output of this program?import java.io.*; public class InputStream_Example { public static void main(String args[]) throws IOException { InputStream obj = new FileInputStream("Interviewmania.com"); System.out.print(obj.available()); } }

A. Compilation Error
B. Runtime Error
C. true
D. false
E. None of these
Answer» C. true
15.

What is the output of this program?public class Result { public static void main(String args[]) { StringBuffer strbuf = new StringBuffer("Interview Mania"); StringBuffer strbuf0 = strbuf.reverse(); System.out.println(strbuf0); } }

A. Interview Mania
B. ainaM weivretnI
C. weivretnI
D. ainaM
E. None of these
Answer» C. weivretnI
16.

What is the output of this program?public class Main { public static void main(String args[]) { StringBuffer strbuf = new StringBuffer("Interview"); StringBuffer strbuf0 = new StringBuffer(" Mania"); strbuf.append(strbuf0); System.out.println(strbuf); } }

A. Mania
B. Interview
C. Interview Mania
D. Compilation Error
E. Runtime Error
Answer» D. Compilation Error
17.

What is the output of this program?import java.io.*; public class Chararrayinput_Example { public static void main(String[] args) { String object = "Interview Mania"; int length = object.length(); char p[] = new char[length]; object.getChars(0,length,p,0); CharArrayReader input1 = new CharArrayReader(p); CharArrayReader input2 = new CharArrayReader(p, 0, 3); int K; try { while ((K = input1.read()) != -1) { System.out.print((char)K); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }

A. Interview
B. Mania
C. Interview Mania
D. InterviewMania
E. None of these
Answer» D. InterviewMania
18.

What is the output of this program?import java.io.*; public class files_Example { public static void main(String args[]) { File object = new File("/New Folder/system"); System.out.print(object.getParent()); System.out.print(" " + object.isFile()); } }

A. /New
B. Folder false
C. /New false
D. /New Folder false
E. None of these
Answer» E. None of these
19.

What is the output of this program?import java.io.*; public class files_Example { public static void main(String args[]) { File object = new File("/java/system"); System.out.print(object.canWrite()); System.out.print(" " + object.canRead()); } }

A. false false
B. false
C. true
D. true false
E. None of these
Answer» B. false
20.

What is the output of this program?import java.io.*; public class files_Example { public static void main(String args[]) { File object = new File("/New Folder/system"); System.out.print(object.getAbsolutePath()); } }

A. /New Folder/system
B. /New Folder
C. /system
D. Folder/system
E. None of these
Answer» B. /New Folder
21.

What is the output of this program if input given is InterviewMania ?

A. InterviewMania
B. Mania
C. Interview
D. ManiaInterview
E. None of these
Answer» D. ManiaInterview
22.

What is the output of this program if input given is prstquvwxyz ?

A. prstquvwxyz
B. prstquv
C. prstq
D. quvwxyz
E. None of these
Answer» D. quvwxyz