Java Questions & Answers – Java.lang – Void, Process & System Class

This section of our 1000+ Java MCQs focuses 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
View Answer

Answer: a
Explanation: 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()
View Answer

Answer: b
Explanation: 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
View Answer

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

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

Answer: b
Explanation: 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()
View Answer

Answer: c
Explanation: None.

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

Answer: d
Explanation: 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?

advertisement
  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
View Answer

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

advertisement
$ 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: a
Explanation: 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

Sanfoundry Global Education & Learning Series – Java Programming Language.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.