Java Questions & Answers – Java.lang – System Class Advance

This set of Java Multiple Choice Questions & Answers (MCQs) focuses on “System Class Advance”.

1. Which of these exceptions is thrown by methods of System class?
a) IOException
b) SystemException
c) SecurityException
d) InputOutputException
View Answer

Answer: c
Explanation: System class methods throw SecurityException.

2. Which of these methods initiates garbage collection?
a) gc()
b) garbage()
c) garbagecollection()
d) Systemgarbagecollection()
View Answer

Answer: a
Explanation: None.

3. Which of these methods loads the specified dynamic library?
a) load()
b) library()
c) loadlib()
d) loadlibrary()
View Answer

Answer: a
Explanation: load() methods loads the dynamic library whose name is specified.
advertisement
advertisement

4. Which of these method can set the out stream to OutputStream?
a) setStream()
b) setosteam()
c) setOut()
d) streamtoOstream()
View Answer

Answer: c
Explanation: None.

5. Which of these values are returns under the case of normal termination of a program?
a) 0
b) 1
c) 2
d) 3
View Answer

Answer: a
Explanation: None.

6. What will be the output of the following Java program?

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

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

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

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

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

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

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

a) ABCDEF ABCDEF
b) ABCDEF GHIJKL
c) ABCDEF GHIABC
d) GHIJKL GHIJKL
View Answer

Answer: c
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 GHIABC

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

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

a) ABCDEF ABCDEF
b) ABCDEF GHIJKL
c) ABCDEF GHIABC
d) ABCDEF GHICDL
View Answer

Answer: d
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 GHICDL

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

  1.     import java.lang.System;
  2.     class Output 
  3.     {
  4.         public static void main(String args[])
  5.         {
  6.             System.exit(5);
  7.         }
  8.     }

a) 0
b) 1
c) 4
d) 5
View Answer

Answer: d
Explanation: None.

Sanfoundry Global Education & Learning Series – Java Programming Language.

To practice all areas of Java language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

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.