Menu
Question Index
...

What will be the output of the following program?

import java.lang.annotation.*;
import java.lang.reflect.*;
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation {
    int value();
}
class Hello {
    @MyAnnotation(value = 10)
    public void goodEveng() {
        System.out.println("hello annotation");
    }
}
class HelloAnnotation {
    public static void main(String args[]) throws Exception {
        Hello h = new Hello();
        Method m = h.getClass().getMethod("goodEveng");
        MyAnnotation myAnn = m.getAnnotation(MyAnnotation.class);
        System.out.println("Prints " + myAnn.value());
    }
}


Prints hello annotation
Prints 10
Prints hello annotation
Prints 10
Some other output
Output can not determined
Compilation Error or Runtime Error

Doubts

Problems

Topic: Other Advanced Topics In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App