Java MCQs on Void, Process & System classes of Java Programming Language.
1. Which of these class have only one field ‘TYPE’? Answer: a 2. Which of the following method of Process class can terminate a process? Answer: b 3. Standard output variable ‘out’ is defined in which class? Answer: d 4. Which of these class can encapsulate an entire executing program? Answer: b 5. Which of the following is method of System class is used to find how long a program takes to execute? Answer: c 6. Which of these class holds a collection of static methods and variables? Answer: d 7. What will be the output of the following Java code? a) 0 8. What will be the output of the following Java code? a) ABCDEF ABCDEF 9. What will be the output of the following Java code? a) ABCDEF GHIJKL 10. What will be the output of the following Java code? a) ABCDEF GHIJKL
a) Void
b) Process
c) System
d) Runtime
Clarification: The Void class has one field, TYPE, which holds a reference to the Class object for the type void.
a) void kill()
b) void destroy()
c) void terminate()
d) void exit()
Clarification: Kills the subprocess. The subprocess represented by this Process object is forcibly terminated.
a) Void
b) Process
c) Runtime
d) System
Clarification: Standard output variable ‘out’ is defined in System class. out is usually used in print statement i:e System.out.print().
a) Void
b) Process
c) Runtime
d) System
Clarification: None.
a) currenttime()
b) currentTime()
c) currentTimeMillis()
d) currenttimeMillis()
Clarification: None.
a) Void
b) Process
c) Runtime
d) System
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.
class Output
{
public static void main(String args[])
{
long start, end;
start = System.currentTimeMillis();
for (int i = 0; i < 10000000; i++);
end = System.currentTimeMillis();
System.out.print(end - start);
}
}
b) 1
c) 1000
d) System Dependent
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
class Output
{
public static void main(String args[])
{
byte a[] = { 65, 66, 67, 68, 69, 70 };
byte b[] = { 71, 72, 73, 74, 75, 76 };
System.arraycopy(a , 0, b, 0, a.length);
System.out.print(new String(a) + " " + new String(b));
}
}
b) ABCDEF GHIJKL
c) GHIJKL ABCDEF
d) GHIJKL GHIJKL
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
class Output
{
public static void main(String args[])
{
byte a[] = { 65, 66, 67, 68, 69, 70 };
byte b[] = { 71, 72, 73, 74, 75, 76 };
System.arraycopy(a, 2, b, 1, a.length-2);
System.out.print(new String(a) + " " + new String(b));
}
}
b) ABCDEF GCDEFL
c) GHIJKL ABCDEF
d) GCDEFL GHIJKL
Clarification: None.
Output:
$ javac Output.java
$ java Output
ABCDEF GCDEFL
class Output
{
public static void main(String args[])
{
byte a[] = { 65, 66, 67, 68, 69, 70 };
byte b[] = { 71, 72, 73, 74, 75, 76 };
System.arraycopy(a, 1, b, 3, 0);
System.out.print(new String(a) + " " + new String(b));
}
}
b) ABCDEF GCDEFL
c) GHIJKL ABCDEF
d) GCDEFL GHIJKL
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