Which two of the following are legal declarations of an abstract class and interfaces

1. 

Which two of the following are legal declarations for nonnested classes and interfaces?

1 final abstract class Test {}

2 public static interface Test {}

3 final public class Test {}

4 protected abstract class Test {}

5 protected interface Test {}

6 abstract public class Test {}

[A]. 1 and 4
[B]. 2 and 5
[C]. 3 and 6
[D]. 4 and 6

Answer: Option C

Explanation:

(3), (6). Both are legal class declarations.

(1) is wrong because a class cannot be abstract and final—there would be no way to use such a class. (2) is wrong because interfaces and classes cannot be marked as static. (4) and (5) are wrong because classes and interfaces cannot be marked as protected.


Page 2


Page 3

  • A Compilation fails due to an error on line 3
  • B A
  • C Compilation fails due to an error on line 8
  • D null
  • B


    Page 4

    • A test-name
    • B Compilation fails due to an error on lines 1
    • C Compilation fails due to an error on lines 2
    • D Compilation succeed but Runtime Exception
  • C


    Page 5


    Page 6

    • A Program will compile and execute successfully and prints
    • B Compilation error as class can not be declared as abstract.
    • C Program compiles but leads to runtime exception.
    • D Compilation error occurs as the abstract class TestAbstract contains a non-abstract method.
  • A


    Page 7

    • A The code will lead to a compilation error as declaration of the display method has been provided in two interface.
    • B The code will lead to a compilation error due to public modifier while declaring the display method.
    • C The code will compile and execute successfully showing the output Welcome to Examveda.
    • D The code will lead to a compilation error as the display method is not declared as abstract.
  • C


    Page 8

    • A Thread(Runnable threadOb, int priority)
    • B Thread(int priority)
    • C Thread(Runnable threadOb, String threadName)
    • D Thread(String threadName, int priority)
  • C


    Page 9

    • A start()
    • B run()
    • C init()
    • D go()
  • B


    Page 10

    • A Extending the thread class.
    • B Implementing Runnable interface.
    • C Both of the above
    • D None of these
  • C


    Page 11

    • A The program does not compile because this cannot be referenced in a static method.
    • B The program compiles fine, but it does not print anything because t does not invoke the run() method
    • C The program compiles and runs fine and displays test on the console.
    • D None of the above
  • A


    Page 12

    • A The program will not compile because it does not implement the run() method.
    • B The program will not compile because it does not contain abstract methods.
    • C The program compiles fine.
    • D None of the above
  • C


    Page 13

    • A run-a
    • B run-a run-a
    • C Compilation fails with an error at line 6
    • D Compilation succeed but Runtime Exception
  • D


    Page 14

    • A run-test run-test
    • B run-test
    • C Compilation fails due to an error on line 4
    • D Compilation fails due to an error on line 7
  • A


    Page 15


    Page 16

    • A The program has a compilation error because t is defined in both the main() method and the constructor Test().
    • B The program compiles fine, but it does not run because you cannot use the keyword this in the constructor.
    • C The program compiles and runs and displays nothing.
    • D The program compiles and runs and displays test.
  • D