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.
Which of the following is not a type of annotation in java ?
Correct
Incorrect
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
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
Question 4 of 15
4. Question
Which of the following annotations will contain no methods in it ?
Correct
Incorrect
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
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
Question 7 of 15
7. Question
Which of the following is not true about annotations in java ?
Correct
Incorrect
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
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
Question 10 of 15
10. Question
Which of the following eliminates the warnings raised by the compiler ?
Correct
Incorrect
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
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
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
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
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.
Your opinion matters Please write your valuable feedback about DataFlair on Google
DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.