R4RIN
Articles
Java 8
MCQS
Java MCQ Quiz Hub
Java Mcq Question Set 8
Choose a topic to test your knowledge and improve your Java skills
1. Which of the following declares an abstract method in an abstract Java class?
public abstract void method() {}
public abstract void method();
public abstract void method();
public abstract method();
2. Which of the following statements regarding abstract classes are true?
An abstract class can be extended.
A subclass of a non-abstract superclass can be abstract.
A subclass can override a concrete method in a superclass to declare it abstract.
All of the above
3. Which of the following is a correct interface?
abstract interface A {abstract void
abstract interfaceA{print();
interface A { void
None of these
4. Given the following piece of code: public interface Guard{void doYourJob(); } abstract public class Dog implements Guard{ } which of the following statements is correct?
This code will not compile, because in the declaration of class Dog we must use the keyword extends instead of implements.
This code will compile without any errors.
This code will not compile, because class Dog must implement method doYourJob() from interface Guard.
This code will not compile, because method doYourJob() in interface Guard must be defined abstract.
5. Runnable is a _____ .
interface
method
class
abstract class
6. Which is true?
"X extends Y" is correct for all combinations of X and Y being classes and/or interfaces
"X extends Y" is correct if X and Y are either both classes or both interfaces
"X extends Y" is correct if and only if X is a class and Y is an interface
"X extends Y" is correct if and only if X is an interface and Y is a class
7. The concept of multiple inheritance is implemented in Java by
Extending one class and implementing one or more interfaces.
Implementing two or more interfaces.
Both of the above
None
8. The class at the top of exception class hierarchy is .................
Exception
ArithmeticException
Object
Throwable
9. In which of the following package Exception class exist?
java.lang
java.io
java.util
java.file
10. Exception generated in try block is caught in ........... block.
finally
catch
throws
throw
11. Which keyword is used to explicitly throw an exception?
catch
throw
try
throwing
12. Which exception is thrown when divide by zero statement executes?
NullPointerException
NumberFormatException
ArithmeticException
None of these
13. Which keyword is used to specify the exception thrown by method?
throws
throw
finally
catch
14. Which of the following blocks execute compulsorily whether exception is caught or not.
throw
throws
catch
finally
15. What happen in case of multiple catch blocks?
The superclass exception must be caught first.
The superclass exception cannot caught first.
Either super or subclass can be caught first.
None of these
16. Which exception is thrown when an array element is accessed beyond the array size?
ArrayIndexOutOfBoundsExceptions
ArrayIndexOutOfBounds
ArrayElementOutOfBounds
None of these
17. public class Test{public static void main(String args[]){ int a = Integer.parseInt("four"); }}} Which exception could be handled by the catch block for above?
NumberFormatException
IllegalStateException
ClassCastException
ArrayIndexOutOfBoundsException
18. try{ File f = new File("a.txt"); }catch(Exception e){ }catch(IOException io){ } Is this code create new file name a.txt ?
TRUE
FALSE
Compilation Error
None of these
19. In java a thread can be created by ..........
Implementing Runnable interface.
Extending the thread class.
Both of the above
None of these
20. When a class extends the Thread class ,it should override ............ method of Thread class to start that thread.
init()
go()
start()
run()
21. Which of the following constructor of class Thread is valid one?
Thread(Runnable threadOb, String threadName)
Thread(Runnable threadOb, int priority)
Thread(String threadName, int priority)
Thread(int priority)
22. Analyze the following code: public abstract class Test implements Runnable{ public void doSomething() { }; }
The program will not compile because it does not contain abstract methods.
The program will not compile because it does not implement the run() method.
The program compiles fine.
None of the above
23. Analyze the following code: public class Test implements Runnable{public static void main(String[] args){Test t = new Test(); t.start(); }public void run() { } }
The program compiles and runs fine.
The program does not compile because the start() method is not defined in the Test class.
The program compiles, but it does not run because the start() method is not defined.
The program compiles, but it does not run because the run() method is not implemented
24. �Which of the following are methods of the Thread class?
yield()
sleep(long msec)
stop()
All of the above
25. Output : public class Test implements Runnable{public void run(){System.out.print("go");}public static void main(String arg[]){Thread t = new Thread(new Test()); t.run(); t.run(); t.start();}}
An exception is thrown at runtime.
26. System class is defined in .................
java.lang package
java.awt package
java.util package
java.io package
27. try{File f = new File("a.txt"); }catch(Exception e){ }catch(IOException io){ } Is this code create new file name a.txt ?
TRUE
FALSE
Compilation Error
None of these
28. Which of these classes defined in java.io and used for file-handling are abstract?
InputStream
Reader
Both (a) and (b)
None of these
29. When comparing java.io.BufferedWriter and java.io.FileWriter, which capability exist as a method in only one of two ?
writting a line separator to the streamwritting a line separator to the stream
writting to the stream
flushing the stream
closing the stream
30. What is the range of data type short in Java?
-32768 to 32767
-128 to 127
-2147483648 to 2147483647
None of these
31. What is the range of data type byte in Java?
-128 to 127
-32768 to 32767
-2147483648 to 2147483647
None of these
32. An expression involving byte, int, and literal numbers is promoted to which of these?
long
int
byte
float
33. Which of these literals can be contained in a data type float variable?
3.40E-50
1.7e-308
1.7e+308
3.40E-38
34. Which data type value is returned by all transcendental math functions?
long
double
float
int
35. What is the numerical range of a char in Java?
0 to 65535
-128 to 127
0 to 256
0 to 32767
36. Which of these coding types is used for data type characters in Java?
ISO-LATIN-1
UNICODE
ASCII
None
37. Which of these values can a boolean variable contain?
True & False
Any integer value
0 & 1
Both of these
38. Which of these occupy first 0 to 127 in Unicode character set used for characters in Java?
ISO-LATIN-1
ASCII
Both a & b
None
39. Which one is a valid declaration of a boolean?
boolean b1 = 1;
boolean b2 = false;
boolean b3 = false;
boolean b4 = true
40. Output : class mainclass { public static void main(String args[]) { boolean var1 = true; boolean var2 = false; if (var1) System.out.println(var1); else System.out.println(var2); } }
TRUE
0
1
FALSE
41. Which of these functions is called to display the output of an applet?
print()
display()
PrintApplet()
displayApplet()
42. Which of these methods can be used to output a sting in an applet?
print()
display()
drawString()
transient()
43. What does AWT stands for?
All Writing Tools
All Window Tools
Abstract Writing Toolkit
Abstract Window Toolkit
44. Which of these methods is a part of Abstract Window Toolkit (AWT) ?
print()
display()
drawString()
transient()
45. Which of these modifiers can be used for a variable so that it can be accessed from any thread or parts of a program?
global
transient
volatile
None
46. Which of these operators can be used to get run time information about an object?
Info
instanceof
getInfo
getinfoof
47. Which of these packages contain all the collection classes?
java.util
java.net
java.awt
java.lang
Submit