Tuesday, November 17, 2015
Saturday, October 31, 2015
Strings in java are called by value not reference
Why?
Because String is immutable.
Because String is immutable.
Assert in java
which line is an example of an inappropriate use of assertions? | |||||||||||||||||
Answer: Option D
Explanation:
Assert statements should not cause side effects. Line 22 changes the value of z if the assert statement is false.
Option A is fine; a second expression in an assert statement is not required.
Option B is fine because it is perfectly acceptable to call a method with the second expression of an assert statement.
Option C is fine because it is proper to call an assert statement conditionally.
|
Output of program
| |||||||||||||||||
Answer: Option D
Explanation:
The foo() method returns void. It is a perfectly acceptable method, but because it returns void it cannot be used in an assert statement, so line 18 will not compile.
Learn more problems on : Assertions
Discuss about this problem : Discuss in Forum
http://www.indiabix.com/online-test/java-programming-test/61 |
Friday, October 30, 2015
Thread And Runnable both have run method which one will be called?
| |||||||||||||||||
Answer: Option A
Explanation:
If a Runnable object is passed to the Thread constructor, then the run method of theThread class will invoke the run method of the Runnable object.
In this case, however, the run method in the Thread class is overridden by the run method in MyThread class. Therefore the run() method in MyRunnable is never invoked.
Both times, the run() method in MyThread is invoked instead.
Reference: http://www.indiabix.com/online-test/java-programming-test/61
|
Subscribe to:
Comments (Atom)
