Enthuware Flashcards
Can a catch block follow a finally block?
No, the order is always try/catch/finally
If you just change a return type of a method, is this proper overloading?
No, you can’t just change the return type, you must change some of the parameters
What does flow control mean?
A for loop
int [] [] [] ia = new int [7] [3] [5]
What will ia.length output?
7
length doesn’t determine the dimensions but will do the length of the first array
For strings created with non-strings, what must part of the creation to ensure successful compilation?
Part of it must be a string
Will this compile?
new Short(9)
No, no constructor in Short wrapper class will take int value
What must s be?
s instanceOf Short
s must be an object
Is StringBuilder a final class?
Yes
What are all methods of String?
Final
What does byte * byte return?
int
What will this output be?
short += int
It will do a cast to short
For overridden methods, what must the return be?
It must be the same of the covarient (subclass)
What is happening here?
return (long) b3 / d * 3
Cast applies only to b3, not whole computation
Can continue occur inside a switch statement?
No
Where can breaks occur?
Switch statement While Do For Enhanced For
Can constructors have a return type
No
If method is called by super() in constructor, which method should be used, the object method or the reference method?
The object method!
Is this ok?
public static void do(){//many lines of code}
No, do is a reserved word
What is the protection hierarchy?
public
protected
default
private
What is a trim - a String method or a StringBuilder method?
A String method
What is append - a String method or a StringBuilder method?
A StringBuilder method
What is meant by a virtual call?
A call made at runtime
What is the range of bytes?
-128 to 127
What are the two things you must ensure when throwing?
- it is within a valid try-catch statement
- method has a throws clause
What will this add?
ArrayList addAll(1,1)
Adds from point 1 to 1 exclusive hence adds nothing
Do switch statements need defaults?
No
Is an empty switch blocks valid?
Yes
What access modifiers can top level classes not have?
private
protected
Which has a reverse method - String or StringBuilder
StringBuilder
Can constructors throw exceptions?
Yes
What does prefix 0b/0B mean?
Binary
Is appends a StringBuilder, StringBuffer or String method?
StringBuilder and StringBuffer
Is intern a StringBuilder, StringBuffer or String method?
String
Can charAt take a char value?
Yes, but it will promote to an int
What must happen to finals?
- must be initialized in init blocks
- initialized in every constructor.
Can overriding methods declare no exceptions?
Yes, they can opt to declare no exceptions
Can case statements in a switch be the same value?
No, they cannot be the same value
Are these two the same?
case 1000000
case 1_000_000
Yes, and that is illegal
Can arrays be created with zero length?
Yes
What must happen to override methods?
Access modifiers must be less or equally as restrictive and return types must match
Can static and non-static methods have the same name?
No, each method must have a unique name
What is true about wrapper objects?
They are always immutable
What can variables not be declared as?
abstract or native
What can varargs (…) take?
Nothing to the largest array
Is $ an operator?
No
Is ~ an operator?
Yes
What must happen to a method signature for a method that isn’t suppose to return anything
It must specify void
Will this work?
for(;;)
Yes, it’s an infinite loop but it is valid
If a string starts as a null, and then gets other string values, will it equals an other string which started life as a string containing the values?
No, because it started as null, it will be different to the other string
Can a constructor be final?
No
Can static methods also be abstract
No
If original method does not throw a checked exception, what can an overridden method throw?
Runtime Exception
Error
Not a checked exception
How can char variables be assigned to shorts?
With explicit casting
What is true about chars and shorts going into each other?
They require specific casting
What is true for all member fields?
They are auto-initialised to default values - 0, 0.0, null, etc
What is true for overloaded methods where the caller method parameters could fit into more than one overloaded method?
It will call the most specific one
Which one is allowed?
int a = b = c = 100;
int a, b, c; a = b =c = 100;
The second, as the values are initialised first beforehand
Does Stringbuilder have a delete method?
Yes
Does StringBuilder have a setCapacity or ensureCapacity method?
ensureCapacity
Are floating point suffixes used on binary numbers?
No
Are L suffixes used on binary numbers?
Yes they can be
Is this valid?
String String = “String”;
Yes, perfectly valie
What is the outcome?
int i =0;
ia[i] = i = 30;
is[0] = 30
What happens when char is auto-initialised as an instance variable?
It gets set to 0 which is an empty space
Is args ever NULL
No, it will always have a length of at least 0
Is this valid?
for (final Object o: a)
Yes, final is the only modifier allowed in this enhance for loop statement
Can you specify the visibility of local variables?
No
Can if statements have empty - just colon - statements?
Yes
Can synchronised ever be applied to a class?
No
Can synchronised ever be applied to a variable?
No
Can synchronised ever be applied to a method or block?
Yes, synchronised can only be applied to a method or block