250+ TOP MCQs on Java.lang – Void, Process & System Class and Answers

Java MCQs on Void, Process & System classes of Java Programming Language.

1. Which of these class have only one field ‘TYPE’?
a) Void
b) Process
c) System
d) Runtime

Answer: a
Clarification: The Void class has one field, TYPE, which holds a reference to the Class object for the type void.

2. Which of the following method of Process class can terminate a process?
a) void kill()
b) void destroy()
c) void terminate()
d) void exit()

Answer: b
Clarification: Kills the subprocess. The subprocess represented by this Process object is forcibly terminated.

3. Standard output variable ‘out’ is defined in which class?
a) Void
b) Process
c) Runtime
d) System

Answer: d
Clarification: Standard output variable ‘out’ is defined in System class. out is usually used in print statement i:e System.out.print().

4. Which of these class can encapsulate an entire executing program?
a) Void
b) Process
c) Runtime
d) System

Answer: b
Clarification: None.

5. Which of the following is method of System class is used to find how long a program takes to execute?
a) currenttime()
b) currentTime()
c) currentTimeMillis()
d) currenttimeMillis()

Answer: c
Clarification: None.

6. Which of these class holds a collection of static methods and variables?
a) Void
b) Process
c) Runtime
d) System

Answer: d
Clarification: System class holds a collection of static methods and variables. The standard input, output and error output of java runtime is stored in the in, out and err variables of System class.

7. What will be the output of the following Java code?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             long start, end;   
  6.             start = System.currentTimeMillis();
  7.             for (int i = 0; i < 10000000; i++);
  8.             end = System.currentTimeMillis();
  9.             System.out.print(end - start);
  10.         }
  11.     }

a) 0
b) 1
c) 1000
d) System Dependent

Answer: d
Clarification: end time is the time taken by loop to execute it can be any non zero value depending on the System.
Output:

$ javac Output.java
$ java Output
78

8. What will be the output of the following Java code?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             byte a[] = { 65, 66, 67, 68, 69, 70 };
  6.             byte b[] = { 71, 72, 73, 74, 75, 76 };  
  7.             System.arraycopy(a , 0, b, 0, a.length);
  8.             System.out.print(new String(a) + " " + new String(b));
  9.         }
  10.     }

a) ABCDEF ABCDEF
b) ABCDEF GHIJKL
c) GHIJKL ABCDEF
d) GHIJKL GHIJKL

Answer: a
Clarification: System.arraycopy() is a method of class System which is used to copy a string into another string.
Output:

$ javac Output.java
$ java Output
ABCDEF ABCDEF

9. What will be the output of the following Java code?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             byte a[] = { 65, 66, 67, 68, 69, 70 };
  6.             byte b[] = { 71, 72, 73, 74, 75, 76 };  
  7.             System.arraycopy(a, 2, b, 1, a.length-2);
  8.             System.out.print(new String(a) + " " + new String(b));
  9.         }
  10.     }

a) ABCDEF GHIJKL
b) ABCDEF GCDEFL
c) GHIJKL ABCDEF
d) GCDEFL GHIJKL

Answer: b
Clarification: None.
Output:

$ javac Output.java
$ java Output
ABCDEF GCDEFL

10. What will be the output of the following Java code?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             byte a[] = { 65, 66, 67, 68, 69, 70 };
  6.             byte b[] = { 71, 72, 73, 74, 75, 76 };  
  7.             System.arraycopy(a, 1, b, 3, 0);
  8.             System.out.print(new String(a) + " " + new String(b));
  9.         }
  10.     }

a) ABCDEF GHIJKL
b) ABCDEF GCDEFL
c) GHIJKL ABCDEF
d) GCDEFL GHIJKL

Answer: a
Clarification: Since last parameter of System.arraycopy(a,1,b,3,0) is 0 nothing is copied from array a to array b, hence b remains as it is.
Output:

$ javac Output.java
$ java Output
ABCDEF GHIJKL

Leave a Reply

Your email address will not be published. Required fields are marked *