Menu
Topics Index
...
`

Annotation


If you need explanation Read this topic

If you need Answer Take test on this topic

Annotation
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());
    }
}

A. Prints hello annotation
Prints 10
B. Prints hello annotation
C. Prints 10
D. Some other output
E. Output can not determined
F. Compilation Error or Runtime Error
Topic: Other Advanced Topics In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

A

Posted by Rathod Ajay    2014-06-30 12:49:26


Ans is C..here we are accesig the value wth MyAnnatation reference, in class Hello we set to 10 so wen we cal that 10 wil getprinted

Posted by Uday Kumar    2014-06-30 13:05:39


ans c. myannotatn  having  1 int value() method declard

by caling hello class annotatn value is assignd.
m is assignd to suitable methd using annotatn intrfac
thn ptints result

Posted by Maheshwari Natarajan    2014-06-30 13:08:17


Congratulations Uday Kumar. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-07-01 04:13:38


© meritcampus 2019

All Rights Reserved.

Open In App