- Remember that a byte is signed with the leftmost bit representing the sign.
Answer:
- What are the casting capabilities of the compound assignment operator +=?
Answer:
The compound assignment operator += lets you add it to the value of b without putting in an explicit cast.
-
What do the following compound assignment operators result in?
+= -= *= /=
Answer:
package com.java.operators;
public class CompoundOperators {
double myDouble2 = 10.2;
int a = 10;
int b = a;
float float1 = 10.2F;
float float2 = float1;
public void math() {
b += a;
System.out.println(b);
a = b = 10;
System.out.println(a);
b /= a;
System.out.println(b);
}
public static void main(String[] args) {
CompoundOperators c1 = new CompoundOperators();
c1.math();
}
}
Output:
20
10
1
-
What is the rule regarding inheritance for the assignment of types?
Answer:
The rule is that you can assign a subclass of the declared type, but not a superclass of the declared type.
- What is the
java.lang.ClassCastException?
Answer
Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance.
For example, the following code generates a ClassCastException:
Object x = new Integer(0);
System.out.println((String)x);
-
What are the 4 basic scopes?
Answer:
- Static variables
- Instance variables
- Local Variables
- Block variables
- What is The most common reason for scoping errors?
Answer:
The most common reason for scoping errors is when you attempt to access a variable that is not in scope.
-
Can Unicode be assigned to the following wrapper objects?
- Integer
- Long
- Float
- Double
Answer:
Only if you use a cast.
package com.java.assignments;
public class UnicodeAssign {
char a = 'a';
char letterN = '\u004E';
public static void main(String[] args) {
Integer I1 = (int) '\u004E';
Long L1 = (long) '\u004E';
Float f1 = (float) '\u004E';
Double d1 = (double) '\u004E';
}
}
- What are local variables sometimes called ?
Answer:
Local variables are sometimes called
- stack
- temporary
- automatic
- method variables
The rules for these variables are the same regardless of what you call them.
- What is the scope of instance variables?
Answer:
Instance variables (also called member variables) are variables defined at the class level.