Loading, please wait...

Core Java Multiple Choice Questions And Answers

Search here for MCQs

Here you will get Java Quiz as Multiple Choice Questions And Answers for you next job or exam

Core Java Multiple Choice Questions And Answers

Are you preparing for the next job interviews? If yes, trust me this post will help you also we'll suggest you check out a big collection for Programming Full Forms that may help you in your interview:

List of Programming Full Forms 

1. What is the result?

public class MyThread implements Runnable
{
public void run()
{
System.out.println("running");
}
public static void main(String args[])
{
Thread t= new Thread(new MyThread());
t.run();
t.run();
t.start();
}
}
  • Compilation fails
  • An Exception is thrown at runtime
  • The code executes and prints "running"
  • The code executes and prints "runningrunning"
  • The code executes and prints "runningrunningrunning"

2. Which two statements are true about has-a and is-a relationships? (choose two)

  • Inheritance represents an is-a relationship
  • Inheritance represents an has-a relationship
  • Interfaces must be used when creating a has-a relationship
  • Instance variables can be used when creating a has-a relationship

3. What can directly access and change the value of the variable name?

package p1;

class Target
{
public String name = "hello";
}
  • any class
  • only the Target class
  • any class in the p1 package
  • any class that extends Target

4. Which three statements are true? (choose three)

  • A final method in class x can be abstract if and only if X is abstract
  • A protected method in class x can be overridden by any subclass of x
  • A private static method can be called only within other static methods in class X
  • A non-static public final method in class X can be overridden in any subclass of X
  • A public static method in class X can be called by a subclass of X without explicitly referencing the class x
  • A method with the same signature as a private final method in class X can be implemented in a subclass of X

5. What is the result?

class SimpleCalc
{
public int value;
public void calculate()
{
value +=7;
}
}
public class MultiCalc extends SimpleCalc
{
public void calculate()
{
value -=3;
}
public void calculate(int multiplier)
{
calculate();
super.calculate();
value *= multiplier;
}
public static void main(String args[])
{
MultiCalc calculator = new MultiCalc();
calculator.calculate(2);
System.out.println("Value is: "+ calculator.value);
}
}
  • Value is : 8
  • Compilation fails
  • Value is : 12
  • Value is : -12
  • The code runs with no output
  • An exception is thrown at runtime