Core Java Multiple Choice Questions And Answers
Here you will get Java Quiz as Multiple Choice Questions And Answers for you next job or exam
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
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"
- 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
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
- 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
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