Java Multiple Choice Questions & Answers on Java.lang package System Class Advance for Freshers

1. Which of these exceptions is thrown by methods of System class?

a) IOException
b) SystemException
c) SecurityException
d) InputOutputException
Answer: c

Explanation: System class methods throw SecurityException.
2. Which of these methods initiates garbage collection?

a) gc()
b) garbage()
c) garbagecollection()
d) Systemgarbagecollection()
Answer: a
3. Which of these methods loads the specified dynamic library?

a) load()
b) library()
c) loadlib()
d) loadlibrary()
Answer: a

Explanation: load() methods loads the dynamic library whose name is specified.
4. Which of these method can set the out stream to OutputStream?

a) setStream()
b) setosteam()
c) setOut()
d) streamtoOstream()
Answer: c
5. Which of these values are returns under the case of normal termination of a program?

a) 0
b) 1
c) 2
d) 3
Answer: a
6. What is the output of this program?
  1.     import java.lang.System;
  2.     class Output {
  3.          public static void main(String args[]) {
  4.              long start, end;   
  5.              start = System.currentTimeMillis();
  6.              for (int i = 0; i < 10000000; i++);
  7.              end = System.currentTimeMillis();
  8.              System.out.print(end - start);
  9.         }
  10.     }
a) 0
b) 1
c) 1000
d) System Dependent
Answer: d

Explanation: end time is the time taken by loop to execute it can be any non zero value depending on the System.
7. What is the output of this program?
  1.     import java.lang.System;
  2.     class Output {
  3.         public static void main(String args[]) {
  4.             byte a[] = { 65, 66, 67, 68, 69, 70 };
  5.             byte b[] = { 71, 72, 73, 74, 75, 76 };  
  6.             System.arraycopy(a, 0, b, 0, a.length);
  7.             System.out.print(new String(a) + " " + new String(b));
  8.         }
  9.     }
a) ABCDEF ABCDEF
b) ABCDEF GHIJKL
c) GHIJKL ABCDEF
d) GHIJKL GHIJKL
Answer: a

Explanation: System.arraycopy() is a method of class System which is used to copy a string into another string.
8. What is the output of this program?
  1.     import java.lang.System;
  2.     class Output {
  3.         public static void main(String args[]) {
  4.             byte a[] = { 65, 66, 67, 68, 69, 70 };
  5.             byte b[] = { 71, 72, 73, 74, 75, 76 };  
  6.             System.arraycopy(a, 0, b, 3, a.length - 3);
  7.             System.out.print(new String(a) + " " + new String(b));
  8.         }
  9.     }
a) ABCDEF ABCDEF
b) ABCDEF GHIJKL
c) ABCDEF GHIABC
d) GHIJKL GHIJKL
Answer: c

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

9. What is the output of this program?
  1.     import java.lang.System;
  2.     class Output {
  3.         public static void main(String args[]) {
  4.             byte a[] = { 65, 66, 67, 68, 69, 70 };
  5.             byte b[] = { 71, 72, 73, 74, 75, 76 };  
  6.             System.arraycopy(a, 2, b, 3, a.length - 4);
  7.             System.out.print(new String(a) + " " + new String(b));
  8.         }
  9.     }
a) ABCDEF ABCDEF
b) ABCDEF GHIJKL
c) ABCDEF GHIABC
d) ABCDEF GHICDL
Answer: d

Explanation: System.arraycopy() is a method of class System which is used to copy a string into another string.
10. What value will this program return to Java run-time system?
  1.     import java.lang.System;
  2.     class Output {
  3.         public static void main(String args[]) {
  4.             System.exit(5);
  5.         }
  6.     }
a) 0
b) 1
c) 4
d) 5
Answer: d

Related

Linux Bash Shell Questions & Answers on Arithmetic Expressions for Freshers

1. Which built-in command performs integer arithmetic in bash shell? a) letb) getc) setd) none of the mentioned Answer: a 2. Which expression use the value of the enclosed arithmetic expression? ...

C# Question & Answers on Runtime Type for Freshers

1. Which mechanism among the following helps in identifying a type during the execution of a program? a) Reflectionb) Runtime type IDc) Both Reflection & Runtime type IDd) None of the mentioned...

Linux Shell Programming Questions and Answers on Variables for Freshers

1. In the shell, by default, all variables are considered and stored as a) stringb) integerc) characterd) float Answer: a 2. Which command reads user input from the terminal and assign this value...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item