Question 25)
Which of the following statements are true?
1) The following statement will produce a result of 1. System.out.println( -1 >>>2);
2) Performing an unsigned left shift (<<<) on a negative number will always produce a negative number result <br /> 3) The following statement will produce a result of zero, System.out.println(1 >>1); <br /> 4) All the integer primitives in
java are signed numbers <br /> <br /> Answer to Question 25) <br /> Objective 5.1)<br /> 3) The following statement will produce a result of zero, System.out.println(1 >>1);
Although you might not know the exact result of the operation -1 >>> 2 a knowledge of the way the bits will be shifted will tell
you that the result is not plus 1. (The result is more like 1073741823 ) There is no such Java operator as the unsigned left shift. Although it is normally used for storing characters rather than numbers the char Java primitive is actually an unsigned integer
type.
============
my doubt is the option 4 specifically asks for integer primitives and the answer explains about char Java primitive ....is char an integer primitive ??
-------------------------------------------
Question 57)
Given the following code
class Base {}
class Agg extends Base{
public
String getFields(){
String name = "Agg";
return name;
}
}
public class Avf{
public static void main(String argv[]){
Base a = new Agg();
//Here
}
}
What code placed after the comment //Here will result in calling the getFields method resulting in the output of the string "Agg"?
1) System.out.println(a.getFields());
2) System.out.println(a.name);
3) System.out.println((Base) a.getFields());
4) System.out.println( ((Agg) a).getFields());
Answer
4) System.out.println( ((Agg) a).getFields());
The Base type reference to the instance of the class Agg needs to be cast from Base to Agg to get access to its methods.The
method invoked depends on the object itself, not on the declared type. So, a.getField() invokes getField() in the Base class,
which displays Base.
------
Here Marcus says that method invoked depends on the object itself, not on the declared type, which means the object which is an Agg will invoke its method not the method of the declared type Base....am i right in this understanding, pls explain.