Q: Java object assignment happens by ___.
Solution: Yes. That is the reason why you can change the values of variables of the object using another reference.
Q: Java object passing from one method to another method happens by ___.
Solution: References point to the original objects. So they can change the state of the objects.
Q: In Java Pass by reference ___ is passed even if you are passing a reference to an object.
Solution: Yes. The address is passed automatically by Java. So, Java pundits argue that it is passing a value (Address).
Q: A Java reference is comparable to ___ in C language.
Solution: no solution
Q: ___ is the superclass to all Java classes either user-defined or built-in.
Solution: Yes. java.lang.Object is the superclass to all Java classes.
Q: State TRUE of FALSE. Java objects have built-in methods to handle threads.
Solution: Yes. The methods are wait(), notify() and notifyAll().
Q: What is the output of the below Java program using toString() method? class College { public String toString() { return "College Object"; } } class Testing18 { public static void main(String[] args) { College col = new College(); System.out.println("Printing Object=" + col); } }
Solution: print() and println() methods call toString() method of objects automatically.
Q: What is the output of the below Java program? class Cricket { int runs; } class Testing19 { public static void main(String[] args) { Cricket c1 = new Cricket(); c1.runs = 250; Cricket c2; c2 = c1; c2.runs = 300; System.out.println("Runs= " + c1.runs); } }
Solution: The reference C2 also points to the same object pointed by reference C1.
Q: What is the output of the below Java program? class Wordpress { int posts; } class Testing20 { public static void main(String[] args) { Wordpress wp1 = new Wordpress(); wp1.posts = 25; Wordpress wp2 = wp1; wp1 = null; System.out.println("Posts=" + wp2.posts); } }
Solution: Even if one REFERENCE to the same object is alive, it can be used to access the object. So, wp2 still works even if wp1 is set to null.
You Have Score    | /9 |