Core Java Quiz

Core Java Quiz

 



Core Java Quiz contain set of 10 MCQ questions for Core Java MCQ which will help you to clear beginner level quiz.



 
1. What will happen when an exception occur inside your code?

     1.  Program will terminate without showing any result.
     2.  Program will terminate showing any error message.
     3.   Java will provide a default exception handler, which will print the exception details on the terminal.
     4.   System crashes.

 
2. What should replace kkkk ?
class MyException extends Exception
{
public void method() throws kkkk
{
throw new MyException();
}
}

  1. Error
  2. MyException
  3. RuntimeException
  4. Throws clause isn’t required

 
3. What will happen on running the following code ?
try
{
int arr[]={1,2};
arr[2]=3/0;
System.out.println(a[0]);
}
catch(Exception e)
{
System.out.println(“Exception”);
}
catch(ArithmeticException e)
{
System.out.println(“Divide by Zero”);
}
 

  1. Exception is printed
  2. Divide by Zero is printed
  3. Compilation error
  4. 1 is printed

 
4. Complete the following statement?
If Super class method throws an exception, then Subclass overridden method _____

   1.  Can throw the same exception.
   2. Can throw no exception.
   3. Can throw child class of the exception thrown by Super class method.
   4.  Can throw parent exception of the exception thrown by Super class method.

 
5. Given two files, what will be the Output?
package pack1;
public class A
{
int m = 10;
public int n = 20;
}
 
package pack2;
import pack1.*;
class Test
{
public static void main(String []args)
{
A a = new A();                       // line 7
System.out.println(a.m);  // line 8
System.out.println(a.n);   // line 9
}
}

  1. 10 20
  2. compilation error at line 7
  3. compilation error at line 8
  4. compilation error at line 9

 
6. Fill the blank to compile the code successfully?
abstract class A
{
int a = 100;
public abstract void showA(); }
 
public class B extends A
{
_ _ _ _ _ _ _ _ _         // Fill the blank
 
public static void main(String []args)
{
A objA = new B();
objA.showA();
}
}
 

  1. public abstract void showA() { }
  2. public void showA() { }
  3. void showA() { }
  4. public B showA() { }

 
7. Which of following is a valid class using the given code?
public interface A { public void showA(); }

     1. public class B extends A { public void showA(){} }
     2. public class B implements A { public abstract void showA(){} }
     3. public class B implements A { void showA(){} }
     4. public class B implements A { public void showA(){} }

 
8. String objects are stored in a special memory area known as?

  1. Heap
  2. Stack
  3. String Constant Pool
  4. Method Area

 
9.  What will be the result of given code ?
String str = “Java”;
String str1 = new String(“Java”);
 
System.out.println(str.equals(str1));
System.out.println(str == str1);
System.out.println( str.compareTo(str1) );
 

  1. true true true
  2. true true 0
  3. true false true
  4. true false 0

 
10. Which class is used to create mutable and non-synchronized string?

  1. StringBuffer
  2. StringBuilder
  3. String
  4. StringTokenizer