Site icon DataFlair

Quiz on Java Assert

quiz on java assert

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

Dive into the world of Java assertions and test your knowledge with this interactive quiz! Assertions are a powerful tool for developers, acting like sentries within your code that verify critical assumptions.

By taking this quiz, you’ll embark on a journey to assess your grasp of core assertion concepts. Are you confident in enabling assertions and understanding the conditions that trigger them? Can you distinguish assertion errors from exceptions and identify the valuable information they provide for debugging?

This engaging quiz will challenge your knowledge of these key areas and more, helping you solidify your understanding of how assertions can enhance the robustness and reliability of your Java programs.

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 type of error is raised while not enabling assertions ?

    Correct
    Incorrect
  2. Question 2 of 15
    2. Question

    Which of the following is the correct syntax of assertion ?

    Correct
    Incorrect
  3. Question 3 of 15
    3. Question

    class Main {

    public static void main ( String args [ ] )

    {

    int weight = 60;

    assert weight<=50:”Cannot donate blood”;

    System.out.println(“Can donate blood”);

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  4. Question 4 of 15
    4. Question

    Which of the following throws exceptions in assert statements ?

    Correct
    Incorrect
  5. Question 5 of 15
    5. Question

    class Counting {

    public static void main ( String args [ ] )

    {

    Scanner sc = new Scanner();

    int value = sc.nextInt();

    assert value>30:”cannot be included”;

    System.out.println(value);

    }

    }

    What should be the input to print “cannot be included” in the given program ?

    Correct
    Incorrect
  6. Question 6 of 15
    6. Question

     class Exception {

    public static void main ( String args [ ] )

    {

    float price = 100.0;

    assert price<=100:”Affordable”;

    System.out.println(“not affordable”);

    }

    }

    What will be the output of the program ?

    Correct
    Incorrect
  7. Question 7 of 15
    7. Question

    Which of the following statements are used to enable assertions in the program ?

    Correct
    Incorrect
  8. Question 8 of 15
    8. Question

    class AssertionExample {

    public static void main ( String args [ ] )

    {

    String data = “DataFlair”;

    assert data==”DataFlair”:”String matches”;

    System.out.println(“Strings are not matching.”);

    }

    }

    What should be the executional statement for the given program ?

    Correct
    Incorrect
  9. Question 9 of 15
    9. Question

    class Function {

    public static void main ( String args [ ] )

    {

    String a = “Data”;

    System.out.println(a.isEquals(“Data”) assert);

    System.out.println(“Both are same”);

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  10. Question 10 of 15
    10. Question

    Which of the following is the main usage of assertions in the program ?

    Correct
    Incorrect
  11. Question 11 of 15
    11. Question

    class One {

    public void method( int a )

    {

    assert a<5:”values are very less”;

    System.out.println(a);

    }

    }

    class Two {

    public int function ( int b )

    {

    assert b>5&&<10:”Values are moderate”;

    return b;

    }

    }

    class Three {

    public void demo ( int c )

    {

    assert c>10:”Values are high”);

    System.out.println(c);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    One o = new One();

    Two t = new Two();

    Three obj = new Three();

    o.method(3);

    System.out.println(t.function(7));

    obj.demo(12);

    }

    }

    What will be the output of the program ?

    Correct
    Incorrect
  12. Question 12 of 15
    12. Question

     class Main {

    public static void main ( String args [ ] )

    {

    String message=”DataFlair”;

    assert message.isEquals(“Webservices”);”DataFlair Webservices”);

    System.out.println(message);

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  13. Question 13 of 15
    13. Question

    Which of the following is true about enabling assertions ?

    Correct
    Incorrect
  14. Question 14 of 15
    14. Question

    class Sample {

    public static void main ( String args [ ] )

    {

    float pressure = 90.0;

    assert pressure<80:”Low pressure”;

    System.out.println(“Pressure is normal”);

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  15. Question 15 of 15
    15. Question

     class Main {

    public static void main ( String args [ ] )

    {

    int a = 10;

    int b = 20;

    assert a<15;b>15:a>20:”Not accepted”;

    System.out.println(“Values are accepted”);

    }

    }

    What is the error in the program ?

    Correct
    Incorrect

Summary:

So you’ve put your Java assertion skills to the test! This quiz covered essential topics such as assertion syntax, enabling assertions, and the distinction between assertions and exceptions. By reviewing both your correct and incorrect answers, you can solidify your grasp of assertions and their effective use in Java programming.

Remember, continuous learning is key. Explore additional resources beyond the quiz to deepen your understanding. Consider tutorials, articles, and practice problems to further solidify your knowledge of assertions in Java.

Exit mobile version