Q.1.

Which of the following statements is true?

Q.2.

Which three statements are true?

  1. Assertion checking is typically enabled when a program is deployed.
  2. It is never appropriate to write code to handle failure of an assert statement.
  3. Assertion checking is typically enabled during program development and testing.
  4. Assertion checking can be selectively enabled or disabled on a per-package basis, but not on a per-class basis.
  5. Assertion checking can be selectively enabled or disabled on both a per-package basis and a per-class basis.
Q.3.

Which statement is true?

Q.4.

Which statement is true about assertions in the Java programming language?

Q.5.

Which of the following statements is true?

Q.6.

Which of the following statements is true?

Q.7.

public class Test{
    public static int x;
    public static int foo(int y) 
    {
        return y *    }
    public static void main(String [] args) 
    {
        int z =        assert z >/* Line*/
        assert z >foo(z); /* Line*/
        if ( z < 7 )
            assert z >/* Line*/

        switch (z) 
        {
            caseSystem.out.println("4 ");
            caseSystem.out.println("5 ");
            default: assert z <        }

        if ( z <)
            assert z >z++; /* Line*/
        System.out.println(z);
    }
}
which line is an example of an inappropriate use of assertions?
Q.8.

What will be the output of the program?

public class Test 
{  
    public static void main(String[] args) 
    { 
        int x = 
        assert (x >? "assertion failed" : "assertion passed" ; 
        System.out.println("finished");  
    } 
}
Q.9.

public class Test 
{ 
    public void foo() 
    {
        assert false; /* Line 5 */
        assert false; /* Line 6 */
    } 
    public void bar()
    {
        while(true)
        {
            assert false; /* Line*/
        } 
        assert false;  /* Line*/
    } 
}
What causes compilation to fail?
Q.10.

public class Test 
{ 
    public void foo() 
    {
        assert false; /* Line 5 */
        assert false; /* Line 6 */
    } 
    public void bar()
    {
        while(true)
        {
            assert false; /* Line*/
        } 
        assert false;  /* Line*/
    } 
}
What causes compilation to fail?
Q.11.

What will be the output of the program?

public class Test 
{
    public static int y;
    public static void foo(int x) 
    {
        System.out.print("foo ");
        y = x;
    }
    public static int bar(int z) 
    {
        System.out.print("bar ");
        return y = z;
    }
    public static void main(String [] args ) 
    {
        int t =        assert t > 0 : bar(7);
        assert t > 1 : foo(8); /* Line*/
        System.out.println("done ");
    }
}
Q.12.

What will be the output of the program (when you run with the -ea option) ?

public class Test 
{  
    public static void main(String[] args) 
    {
        int x = 
        assert (x >: "assertion failed"; /* Line 6 */
        System.out.println("finished"); 
    } 
}
Q.13.

public class Test{
    public static int x;
    public static int foo(int y) 
    {
        return y *    }
    public static void main(String [] args) 
    {
        int z =        assert z >/* Line*/
        assert z >foo(z); /* Line*/
        if ( z < 7 )
            assert z >/* Line*/

        switch (z) 
        {
            caseSystem.out.println("4 ");
            caseSystem.out.println("5 ");
            default: assert z <        }

        if ( z <)
            assert z >z++; /* Line*/
        System.out.println(z);
    }
}
which line is an example of an inappropriate use of assertions?