Vidyalelo
Java Programming · all questions

Interfaces and Abstract Classes
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

309

Questions

2/16

Page

Pick an option on a question to see the right answer and solution.

What is the purpose of the "final" keyword in Java?

Select an option to see the answer and solution.

In Java, can an abstract class have constructors?

Select an option to see the answer and solution.

What is the result of the following code snippet?

abstract class MyAbstract {
MyAbstract() {
System.out.println("Constructor");
}
}
class MyClass extends MyAbstract {
public static void main(String[] args) {
MyClass obj = new MyClass();
}
}

Select an option to see the answer and solution.

In Java, can an interface have static methods with implementations?

Select an option to see the answer and solution.

What is the result of the following code snippet?

interface MyInterface {
static void myMethod() {
System.out.println("Static Method");
}
}
class MyClass implements MyInterface {
public static void main(String[] args) {
MyInterface.myMethod();
}
}

Select an option to see the answer and solution.

In Java, can an abstract class have private methods with implementations?

Select an option to see the answer and solution.

What is the result of the following code snippet?

abstract class MyAbstract {
private void myMethod() {
System.out.println("Private Method");
}
}
class MyClass extends MyAbstract {
public static void main(String[] args) {
MyClass obj = new MyClass();
obj.myMethod();
}
}

Select an option to see the answer and solution.

In Java, can an abstract class have static methods with implementations?

Select an option to see the answer and solution.

What is the result of the following code snippet?

abstract class MyAbstract {
static void myMethod() {
System.out.println("Static Method");
}
}
class MyClass extends MyAbstract {
public static void main(String[] args) {
MyAbstract.myMethod();
}
}

Select an option to see the answer and solution.

In Java, can an abstract class have default methods with implementations?

Select an option to see the answer and solution.

Given the following piece of code:
public class School{
        public abstract double numberOfStudent();
}

which of the following statements is true?

Select an option to see the answer and solution.

Which of the following class definitions defines a legal abstract class?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which of the following statements regarding abstract classes are true?

Select an option to see the answer and solution.

Suppose A is an abstract class, B is a concrete subclass of A, and both A and B have a default constructor. Which of the following is correct?
1. A a = new A();
2. A a = new B();
3. B b = new A();
4. B b = new B();

Select an option to see the answer and solution.

Which of the following is a correct interface?

Select an option to see the answer and solution.

Determine output of the following code.
interface A { }

class C { }

class D extends C { }

class B extends D implements A { }

public class Test extends Thread{
        public static void main(String[] args){
                B b = new B();
                if (b instanceof A)
                        System.out.println("b is an instance of A");
                if (b instanceof C)
                        System.out.println("b is an instance of C");
        }
}

Select an option to see the answer and solution.

Given the following piece of code:
public interface Guard{
        void doYourJob();
}
abstract public class Dog implements Guard{ }

which of the following statements is correct?

Select an option to see the answer and solution.

In Java, declaring a class abstract is useful

Select an option to see the answer and solution.

What will be the output?
interface A{
	public void method();
}
class One{
	public void method(){
		System.out.println("Class One method");
	}
}
class Two extends One implements A{
	public void method(){
		System.out.println("Class Two method");
	}
}
public class Test extends Two{
	public static void main(String[] args){
		A a = new Two();
		a.method();		
	}
}

Select an option to see the answer and solution.