Site icon DataFlair

Quiz on Java Annotations

quiz on java annotations

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Annotations are powerful tools in the Java developer’s arsenal, adding metadata to your code to influence its behavior at compile time or runtime. Whether you’re leveraging annotations for dependency injection, framework configuration, or custom validation, a solid understanding of their capabilities is essential.

This interactive quiz will test your knowledge of core Java annotation concepts, helping you identify areas for improvement and solidify your foundation.

Time limit: 0

Quiz Summary

0 of 15 Questions completed

Questions:

Information

You have already completed the quiz before. Hence you can not start it again.

Quiz is loading…

You must sign in or sign up to start the quiz.

You must first complete the following:

Results

Quiz complete. Results are being recorded.

Results

0 of 15 Questions answered correctly

Your time:

Time has elapsed

You have reached 0 of 0 point(s), (0)

Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)

Categories

  1. Not categorized 0%
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  1. Current
  2. Review / Skip
  3. Answered
  4. Correct
  5. Incorrect
  1. Question 1 of 15
    1. Question

    Which of the following is not a type of annotation in java ?

    Correct
    Incorrect
  2. Question 2 of 15
    2. Question

    class Sample {

    public void display() {

    System.out.println(“DataFlair”);

    }

    }

    class Demo extends Sample {

    @override

    public void display()

    {

    System.out.println(“Override display”);

    }

    }

    class Main {

    public static void main ( string args [ ] )

    {

    Demo d = new Demo();

    d.display();

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  3. Question 3 of 15
    3. Question

    @interface

    class Marker {

    @MarkerDemo 

    public void method ()

    {

    Marker m = new Marker();

    if(m.isAnnotationPresent)

    {

    System.out.println(“Annotation is present”);

    }

    else {

    System.out.println(“Annotation is not present”);

    }

    public static void main( String args [ ] )

    {

    method();

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  4. Question 4 of 15
    4. Question

    Which of the following annotations will contain no methods in it ?

    Correct
    Incorrect
  5. Question 5 of 15
    5. Question

    class Override {

    public calculate ( int x , int y )

    {

    return x*y;

    }

    }

    class Function extends Override {

        @override

    public void calculate( int x , int y , int z )

    {

    return x*y*z;

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Override o = new Function();

    o.calculate(10,5,2);

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  6. Question 6 of 15
    6. Question

    class Example {

    public static void main ( String args [ ] )

    {

    @interface Marker

    Marker 

    public void method()

    {

    System.out.println(‘DataFlair”);

    }

    method();

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  7. Question 7 of 15
    7. Question

    Which of the following is not true about annotations in java ?

    Correct
    Incorrect
  8. Question 8 of 15
    8. Question

    class Maths {

    @suppressedWarnings (“Unchecked”)

    public int sum ( x , y )

    {

    return x+y;

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Maths m = new Maths();

    System.out.println(m.sum(15,16));

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  9. Question 9 of 15
    9. Question

    class Suppressed {

    @SuppressedWarnings(“rawtypes”);

    public void ListType()

    {

    List l = new List();

    l.add(10);

    l.add(100);

    l.add(1000);

    System.out.println(l);

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Suppressed s = new Suppressed();

    s.ListType();

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  10. Question 10 of 15
    10. Question

    Which of the following eliminates the warnings raised by the compiler ?

    Correct
    Incorrect
  11. Question 11 of 15
    11. Question

    class Main {

    public static void main ( String args [ ] )

    {

    method(“DataFlair”);

    }

    @Marker 

    public void method( String a )

    {   

    System.out.println(a);

     

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  12. Question 12 of 15
    12. Question

     class Function {

    @SupressedWarnings(“deprecated”)

    public int Addition( int x , int y )

    {

    return x+y    ;

    }

    }

    class Main {

    public static void main ( String args  [ ] )

    {

    Function f = new Function ();

    int value = f.Addition(1,2);

    System.out.println(value);

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  13. Question 13 of 15
    13. Question

    Which annotations are used to mark methods which should be ignored or methods that can be deleted ?

    Correct
    Incorrect
  14. Question 14 of 15
    14. Question

    class Exception {

    Override

    public void display()   

    {

    System.out.println(“Annotation is included”);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Exception obj = new Exception();

    obj.display();

    }

    }

    What is the error in the program ?

    Correct
    Incorrect
  15. Question 15 of 15
    15. Question

    @interface Multiplication

    class Annotation {

    public static void main ( String args [ ] )

    {

    method();

    }

    @Multiplication

    void method()

    {

    System.out.println(32*32);

    }

    }

    What is the output of the program ?

    Correct
    Incorrect

Summary:

So you’ve taken the Java Annotations Quiz and put your skills to the test! This quiz covered various annotation types, their usage scenarios, and common annotation-based features in Java.

By reviewing both your correct and incorrect answers, you can gain valuable insights into your strengths and weaknesses in this critical domain. Remember, effective learning is an ongoing process. Explore additional resources beyond the quiz to deepen your understanding.

Consider online courses, tutorials, and practice projects to further solidify your grasp of Java annotations and their applications in real-world development.

Exit mobile version