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
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
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
Explanation: 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
View Answer
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
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
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?
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);
}
}
a) 0
b) 1
c) 1000
d) System Dependent
View Answer
Explanation: 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?
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));
}
}
a) ABCDEF ABCDEF
b) ABCDEF GHIJKL
c) GHIJKL ABCDEF
d) GHIJKL GHIJKL
View Answer
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?
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));
}
}
a) ABCDEF GHIJKL
b) ABCDEF GCDEFL
c) GHIJKL ABCDEF
d) GCDEFL GHIJKL
View Answer
Explanation: None.
Output:
$ javac Output.java
$ java Output
ABCDEF GCDEFL
10. What will be the output of the following Java code?
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));
}
}
a) ABCDEF GHIJKL
b) ABCDEF GCDEFL
c) GHIJKL ABCDEF
d) GCDEFL GHIJKL
View Answer
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.
- Check Programming Books
- Practice Information Technology MCQs
- Practice BCA MCQs
- Apply for Java Internship
- Check Java Books