This section of our 1000+ Java MCQs focuses Runtime & ClassLoader classes of Java Programming Language.
1. Which of these classes encapsulate runtime environment?
a) Class
b) System
c) Runtime
d) ClassLoader
View Answer
Explanation: None.
2. Which of the following exceptions is thrown by every method of Runtime class?
a) IOException
b) SystemException
c) SecurityException
d) RuntimeException
View Answer
Explanation: Every method of Runtime class throws SecurityException.
3. Which of these methods returns the total number of bytes of memory available to the program?
a) getMemory()
b) TotalMemory()
c) SystemMemory()
d) getProcessMemory()
View Answer
Explanation: TotalMemory() returns the total number of bytes available to the program.
4. Which of these Exceptions is thrown by loadClass() method of ClassLoader class?
a) IOException
b) SystemException
c) ClassFormatError
d) ClassNotFoundException
View Answer
Explanation: None.
5. What will be the output of the following Java program?
class X
{
int a;
double b;
}
class Y extends X
{
int c;
}
class Output
{
public static void main(String args[])
{
X a = new X();
Y b = new Y();
Class obj;
obj = b.getClass();
System.out.print(obj.getSuperclass());
}
}
a) X
b) Y
c) class X
d) class Y
View Answer
Explanation: getSuperClass() returns the super class of an object. b is an object of class Y which extends class X , Hence Super class of b is X. therefore class X is printed.
Output:
$ javac Output.java $ java Output class X
6. What will be the output of the following Java program?
class X
{
int a;
double b;
}
class Y extends X
{
int c;
}
class Output
{
public static void main(String args[])
{
X a = new X();
Y b = new Y();
Class obj;
obj = b.getClass();
System.out.print(b.equals(a));
}
}
a) 0
b) 1
c) true
d) false
View Answer
Explanation: None.
Output:
$ javac Output.java $ java Output false
7. What will be the output of the following Java program?
class X
{
int a;
double b;
}
class Y extends X
{
int c;
}
class Output
{
public static void main(String args[])
{
X a = new X();
Y b = new Y();
Class obj;
obj = b.getClass();
System.out.print(obj.isInstance(a));
}
}
a) 0
b) 1
c) true
d) false
View Answer
Explanation: Although class Y extends class X but still a is not considered related to Y. hence isInstance() returns false.
Output:
$ javac Output.java $ java Output false
Sanfoundry Global Education & Learning Series Java Programming Language.
- Practice Programming MCQs
- Apply for Computer Science Internship
- Practice Information Technology MCQs
- Check Java Books
- Check Programming Books