Java/Java Mcq Question Set 8 Sample Test,Sample questions

Question:
 What happen in case of multiple catch blocks?

1.The superclass exception must be caught first.

2.The superclass exception cannot caught first.

3.Either super or subclass can be caught first.

4.None of these


Question:
An expression involving byte, int, and literal numbers is promoted to which of these?

1.long

2.int

3.byte

4.float


Question:
Analyze the following code: public abstract class Test implements Runnable{ public void doSomething() { }; }

1.The program will not compile because it does not contain abstract methods.

2.The program will not compile because it does not implement the run() method.

3.The program compiles fine.

4.None of the above


Question:
Analyze the following code: public class Test implements Runnable{public static void main(String[] args){Test t = new Test(); t.start(); }public void run() { } }

1.The program compiles and runs fine.

2.The program does not compile because the start() method is not defined in the Test class.

3.The program compiles, but it does not run because the start() method is not defined.

4.The program compiles, but it does not run because the run() method is not implemented


Question:
Exception generated in try block is caught in ........... block.

1.finally

2.catch

3.throws

4.throw


Question:
Given the following piece of code: public interface Guard{void doYourJob(); } abstract public class Dog implements Guard{ } which of the following statements is correct?

1.This code will not compile, because in the declaration of class Dog we must use the keyword extends instead of implements.

2.This code will compile without any errors.

3.This code will not compile, because class Dog must implement method doYourJob() from interface Guard.

4.This code will not compile, because method doYourJob() in interface Guard must be defined abstract.


Question:
In java a thread can be created by ..........

1.Implementing Runnable interface.

2.Extending the thread class.

3.Both of the above

4.None of these


Question:
In which of the following package Exception class exist?

1.java.lang

2.java.io

3.java.util

4.java.file


Question:
�Which of the following are methods of the Thread class?

1.yield()

2.sleep(long msec)

3.stop()

4.All of the above


Question:
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); } }

1.TRUE

2.0

3.1

4.FALSE


Question:
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();}}

1.An exception is thrown at runtime.

2.


Question:
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?

1.NumberFormatException

2.IllegalStateException

3.ClassCastException

4.ArrayIndexOutOfBoundsException


Question:
Runnable is a _____ .

1.interface

2.method

3.class

4.abstract class


Question:
System class is defined in .................

1.java.lang package

2.java.awt package

3.java.util package

4.java.io package


Question:
The class at the top of exception class hierarchy is .................

1.Exception

2.ArithmeticException

3.Object

4.Throwable


Question:
The concept of multiple inheritance is implemented in Java by

1.Extending one class and implementing one or more interfaces.

2.Implementing two or more interfaces.

3.Both of the above

4.None


Question:
try{ File f = new File("a.txt"); }catch(Exception e){ }catch(IOException io){ } Is this code create new file name a.txt ?

1.TRUE

2.FALSE

3.Compilation Error

4.None of these


Question:
try{File f = new File("a.txt"); }catch(Exception e){ }catch(IOException io){ } Is this code create new file name a.txt ?

1.TRUE

2.FALSE

3.Compilation Error

4.None of these


Question:
What does AWT stands for?

1.All Writing Tools

2.All Window Tools

3.Abstract Writing Toolkit

4.Abstract Window Toolkit


Question:
What is the numerical range of a char in Java?

1.0 to 65535

2.-128 to 127

3.0 to 256

4.0 to 32767


Question:
What is the range of data type byte in Java?

1.-128 to 127

2.-32768 to 32767

3.-2147483648 to 2147483647

4.None of these


Question:
What is the range of data type short in Java?

1.-32768 to 32767

2.-128 to 127

3.-2147483648 to 2147483647

4.None of these


Question:
When a class extends the Thread class ,it should override ............ method of Thread class to start that thread.

1.init()

2.go()

3.start()

4.run()


Question:
When comparing java.io.BufferedWriter and java.io.FileWriter, which capability exist as a method in only one of two ?

1.writting a line separator to the streamwritting a line separator to the stream

2.writting to the stream

3.flushing the stream

4.closing the stream


Question:
Which data type value is returned by all transcendental math functions?

1.long

2.double

3.float

4.int


Question:
Which exception is thrown when an array element is accessed beyond the array size?

1.ArrayIndexOutOfBoundsExceptions

2.ArrayIndexOutOfBounds

3.ArrayElementOutOfBounds

4.None of these


Question:
Which exception is thrown when divide by zero statement executes?

1.NullPointerException

2.NumberFormatException

3.ArithmeticException

4.None of these


Question:
Which is true?

1."X extends Y" is correct for all combinations of X and Y being classes and/or interfaces

2."X extends Y" is correct if X and Y are either both classes or both interfaces

3."X extends Y" is correct if and only if X is a class and Y is an interface

4."X extends Y" is correct if and only if X is an interface and Y is a class


Question:
Which keyword is used to explicitly throw an exception?

1.catch

2.throw

3.try

4.throwing


Question:
Which keyword is used to specify the exception thrown by method?

1.throws

2.throw

3.finally

4.catch


Question:
Which of the following blocks execute compulsorily whether exception is caught or not.

1.throw

2.throws

3.catch

4.finally


Question:
Which of the following constructor of class Thread is valid one?

1.Thread(Runnable threadOb, String threadName)

2.Thread(Runnable threadOb, int priority)

3.Thread(String threadName, int priority)

4.Thread(int priority)


Question:
Which of the following declares an abstract method in an abstract Java class?

1.public abstract void method() {}

2.public abstract void method();

3.public abstract void method();

4.public abstract method();


Question:
Which of the following is a correct interface?

1.abstract interface A {abstract void

2.abstract interfaceA{print();

3.interface A { void

4.None of these


Question:
Which of the following statements regarding abstract classes are true?

1.An abstract class can be extended.

2.A subclass of a non-abstract superclass can be abstract.

3.A subclass can override a concrete method in a superclass to declare it abstract.

4.All of the above


Question:
Which of these classes defined in java.io and used for file-handling are abstract?

1.InputStream

2.Reader

3.Both (a) and (b)

4.None of these


Question:
Which of these coding types is used for data type characters in Java?

1.ISO-LATIN-1

2.UNICODE

3.ASCII

4.None


Question:
Which of these functions is called to display the output of an applet?

1.print()

2.display()

3.PrintApplet()

4.displayApplet()


Question:
Which of these literals can be contained in a data type float variable?

1.3.40E-50

2.1.7e-308

3.1.7e+308

4.3.40E-38


Question:
Which of these methods can be used to output a sting in an applet?

1.print()

2.display()

3.drawString()

4.transient()


Question:
Which of these methods is a part of Abstract Window Toolkit (AWT) ?

1.print()

2.display()

3.drawString()

4.transient()


Question:
Which of these modifiers can be used for a variable so that it can be accessed from any thread or parts of a program?

1.global

2.transient

3.volatile

4.None


Question:
Which of these occupy first 0 to 127 in Unicode character set used for characters in Java?

1.ISO-LATIN-1

2.ASCII

3.Both a & b

4.None


Question:
Which of these operators can be used to get run time information about an object?

1.Info

2.instanceof

3.getInfo

4.getinfoof


Question:
Which of these packages contain all the collection classes?

1.java.util

2.java.net

3.java.awt

4.java.lang


Question:
Which of these values can a boolean variable contain?

1.True & False

2.Any integer value

3.0 & 1

4.Both of these


Question:
Which one is a valid declaration of a boolean?

1.boolean b1 = 1;

2.boolean b2 = false;

3.boolean b3 = false;

4.boolean b4 = true


More MCQS

  1. Java Mcq Question Set 1
  2. Java Mcq Question Set 2
  3. Java Mcq Question Set 3
  4. Java Mcq Question Set 4
  5. Java Mcq Question Set 5
  6. Java Mcq Question Set 6
  7. Java Mcq Question Set 7
  8. Java Mcq Question Set 8
  9. Java Mcq Question Set 9
  10. Java Multiple Choice Questions
  11. DATA TYPES IN JAVA
  12. Classes ,Constructor ,Methods,Inheritance
  13. Java Multiple Choice Questions.
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!