Online Java Compiler By
JavaTpoint.com
//import statements import java.lang.annotation.Annotation; //import annotation import java.lang.annotation.Inherited; //import Inherited import java.lang.annotation.Retention; //import retention import java.lang.annotation.RetentionPolicy; //import retention policy public class ClassgetDeclaredAnnotationExample1 { public static void main(String... args) { Annotation ann = Class1.class.getDeclaredAnnotation(Deprecated.class); // getdeclaredannotation method System.out.println(ann); //print annotation ann = Class1.class.getDeclaredAnnotation(Annotation1.class); // getdeclaredannotation method System.out.println(ann); } @Deprecated public static class Class1 extends SuperClass1 { } @Annotation1 public static class SuperClass1 { } @Retention(RetentionPolicy.RUNTIME) @Inherited private static @interface Annotation1 { } }
Output