1. One of the most common uses of assertions is to ensure that the program remains in a consistent state. True/False?
Ans: True
2. Assertions checks can be turned on and off at runtime, so that programmers don’t have to think during development whether there checks should remain in the code or removed during deployment. True/False
Ans: True
3. The ‘>>>’ operator performs a signed right shift.
Ans: false
4. Assertions can be enabled or disabled for specific packages. True/False.
Ans: True
5. The <, <=, >, >= operators all return a result of ___ type.
Ans: Boolean
6. The ____ operator tests the type of an object at runtime.
Ans: instanceof
7. When assertions are off, they don’t use system resources and only takes little space in the compiled bytecode, but they can be turned on at runtime whenever the software seems to have a problem. True/False
Ans: True
8. If one operand in an operation is a boolean, the other operand can be of integral type.
Ans: False
9. AssertionError is the immediate subclass of
A) java.lang.RuntimeException
B) java.lang.Throwable
C) java.lang.Exception
D) java.lang.Error
Ans: D
10. Assert is not a java keyword. True/False
Ans: false
11. The command for compiling a sourse code using java’s new assertion feature is as follows ___.
A) javac –source 1.3 filename.java
B) javac –source 1.4 filename.java
C) javac filename.java
D) javac –source assert filename.java
Ans: B
12. The ‘&&’ operator might not always evaluate the right hand operand.
Ans: True
13. Assertions in java is an alternative to exception handling.
Ans: false
14. Assertions should not be
used in which of the following cases?
A) to use internal assumptions about the aspect of data structures.
B) To enforce constraints on arguments to provide methods.
C) To check for conditional cases that should never happen, even if you are really sure they can never happen
D) To enforce command- line usage and constraints on arguments to public methods
Ans: D
15. The <<>
Ans: 0
16. It is not possible to enable or disable assertion from the program itself (in source code level). The programmer has to use command line argument java –ea or java –da etc, to indicate whether assertions should be enable or disabled.
True/False
Ans: false
17. By default , assertion mechanism is turned off. True/False.
Ans: True
18. Is line 1 indicating a valid assertion statement in the following code?
Public class AssertionTest{
Public void anyMethod(int argument){
Object testObj=null;
//… somehow get testObj object or construct it.
// now check to make sure you have manage to get one.
assert testObj!=null //line 1
}
}
Ans: Yes
19. Each class contains an “assertion status” flag that tells the system whether assertions are enabled for that class.
Ans: True
20. If double x=42.3 then the value of “x%10” will be ___.
Ans: 2.3
21. Assert expression should not cause side effects. True/False?
Ans: True
22. If int a=35 then the value of “a>>2” will be ___
Ans: 8
23. The “!” operator inverts the value of a Boolean expression.
Ans: True
24. An assertion is a conditional expression that should evaluate to ___, if and only if your code is working correctly.
A) true
B) false
C) void
D) null
Ans: A
25. For the XOR operation, a 1 bit results only if exactly one operand bit is 1.
Ans: True
No comments:
Post a Comment