Enthuware Flashcards

1
Q

Can a catch block follow a finally block?

A

No, the order is always try/catch/finally

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

If you just change a return type of a method, is this proper overloading?

A

No, you can’t just change the return type, you must change some of the parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does flow control mean?

A

A for loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

int [] [] [] ia = new int [7] [3] [5]

What will ia.length output?

A

7

length doesn’t determine the dimensions but will do the length of the first array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

For strings created with non-strings, what must part of the creation to ensure successful compilation?

A

Part of it must be a string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Will this compile?

new Short(9)

A

No, no constructor in Short wrapper class will take int value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What must s be?

s instanceOf Short

A

s must be an object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Is StringBuilder a final class?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are all methods of String?

A

Final

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does byte * byte return?

A

int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What will this output be?

short += int

A

It will do a cast to short

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

For overridden methods, what must the return be?

A

It must be the same of the covarient (subclass)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is happening here?

return (long) b3 / d * 3

A

Cast applies only to b3, not whole computation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Can continue occur inside a switch statement?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Where can breaks occur?

A
Switch statement
While
Do
For
Enhanced For
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Can constructors have a return type

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

If method is called by super() in constructor, which method should be used, the object method or the reference method?

A

The object method!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Is this ok?

public static void do(){//many lines of code}

A

No, do is a reserved word

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the protection hierarchy?

A

public
protected
default
private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is a trim - a String method or a StringBuilder method?

A

A String method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is append - a String method or a StringBuilder method?

A

A StringBuilder method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is meant by a virtual call?

A

A call made at runtime

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the range of bytes?

A

-128 to 127

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What are the two things you must ensure when throwing?

A
  • it is within a valid try-catch statement

- method has a throws clause

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What will this add? ArrayList addAll(1,1)
Adds from point 1 to 1 exclusive hence adds nothing
26
Do switch statements need defaults?
No
27
Is an empty switch blocks valid?
Yes
28
What access modifiers can top level classes not have?
private | protected
29
Which has a reverse method - String or StringBuilder
StringBuilder
30
Can constructors throw exceptions?
Yes
31
What does prefix 0b/0B mean?
Binary
32
Is appends a StringBuilder, StringBuffer or String method?
StringBuilder and StringBuffer
33
Is intern a StringBuilder, StringBuffer or String method?
String
34
Can charAt take a char value?
Yes, but it will promote to an int
35
What must happen to finals?
- must be initialized in init blocks | - initialized in every constructor.
36
Can overriding methods declare no exceptions?
Yes, they can opt to declare no exceptions
37
Can case statements in a switch be the same value?
No, they cannot be the same value
38
Are these two the same? case 1000000 case 1_000_000
Yes, and that is illegal
39
Can arrays be created with zero length?
Yes
40
What must happen to override methods?
Access modifiers must be less or equally as restrictive and return types must match
41
Can static and non-static methods have the same name?
No, each method must have a unique name
42
What is true about wrapper objects?
They are always immutable
43
What can variables not be declared as?
abstract or native
44
What can varargs (...) take?
Nothing to the largest array
45
Is $ an operator?
No
46
Is ~ an operator?
Yes
47
What must happen to a method signature for a method that isn't suppose to return anything
It must specify void
48
Will this work? for(;;)
Yes, it's an infinite loop but it is valid
49
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
50
Can a constructor be final?
No
51
Can static methods also be abstract
No
52
If original method does not throw a checked exception, what can an overridden method throw?
Runtime Exception Error Not a checked exception
53
How can char variables be assigned to shorts?
With explicit casting
54
What is true about chars and shorts going into each other?
They require specific casting
55
What is true for all member fields?
They are auto-initialised to default values - 0, 0.0, null, etc
56
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
57
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
58
Does Stringbuilder have a delete method?
Yes
59
Does StringBuilder have a setCapacity or ensureCapacity method?
ensureCapacity
60
Are floating point suffixes used on binary numbers?
No
61
Are L suffixes used on binary numbers?
Yes they can be
62
Is this valid? String String = "String";
Yes, perfectly valie
63
What is the outcome? int i =0; ia[i] = i = 30;
is[0] = 30
64
What happens when char is auto-initialised as an instance variable?
It gets set to 0 which is an empty space
65
Is args ever NULL
No, it will always have a length of at least 0
66
Is this valid? for (final Object o: a)
Yes, final is the only modifier allowed in this enhance for loop statement
67
Can you specify the visibility of local variables?
No
68
Can if statements have empty - just colon - statements?
Yes
69
Can synchronised ever be applied to a class?
No
70
Can synchronised ever be applied to a variable?
No
71
Can synchronised ever be applied to a method or block?
Yes, synchronised can only be applied to a method or block
72
Can a constructor be overridden?
No
73
What does the equals method of the object do?
It checks to see whether the object references are pointing to the same objects
74
What will happen if a public class is run without the special main method?
It will throw a runtime error for java.lang.NoSuchMethodError
75
Can you have a switch statement of type int and a case statement of type chat?
Yes
76
What must the right side of the instanceOf always be?
An object
77
What must happen with the main and void in the main method signature?
They must always be together
78
What is happening here? int i = 1______3; int p = 1_3;
Both will equal 13
79
Will finally still get executed if System.exit(0) is used within the try?
No, it is the one time that the final block will not get executed
80
What are exceptions used for?
To determine what to do when something goes wrong | Used also for logging
81
Can you instantiate or increment inside a while clause?
No
82
What will happen here and is it valid? for(int i = 0; ; i++) break;
It is valid It will execute once and then stop
83
What are the possible outcomes of charAt() if it needs to throw due to an incorrect value
More than likely StringIndexOutOfBounds exception, but could also throw IndexOutOfBounds exception so can't be sure
84
What happens if you throw without a catch block or throws in the method signature?
It will fail to compile
85
What is java.lang.SecurityException?
A runtime exception
86
Is args ever null?
No
87
Does String have a concat method?
Yes
88
What must happen if the reference method throws an exception but the object method does not?
You still must have a try-catch or throws in place at compile time for obvious reasons
89
How do you import static members of a class?
Using static imports statements
90
Can the main method be declared final?
Yes
91
Can you use the keyword this on static members?
Yes but it is unnecessary
92
Will this compile? double x = 10, double y;
No, the comma is the issue here between two primitive declarations
93
What must happen with final variables?
They must be initialised by init blocks or by every constructor
94
What will happen in this String method .substring(9,15)
Will take from char 9 until character 14, not incorporating character 15
95
What is true for floats?
Always have an f suffix
96
What does the replace method on a String do if there is a change?
Returns a new object
97
What does the repalce method of a String do if there is no change?
Returns the same object
98
What must the left side of an operand be?
An object, not a primative
99
What will happen here? int x2 = x1--;
x2 is assigned the value of x1 and then x1 is decremented
100
What will happen here? if (a = b)...
Will evaluate to true and be grand for an if statement
101
Can booleans, longs, floats and doubles be used in switch statements?
No
102
Can a char be assigned a int value implicitly?
No, implicit narrowing will not work
103
What is the difference between & and &&?
& can have both integral as well as boolean operators, whereas && can only have boolean operators
104
If b and d are different types, will b == d compile?
No
105
Is this valid? block : { beak block; }
Yes
106
Is this valid? { { } }
Yes, valid compound statement
107
Can continue occur within a switch statement?
No
108
If null is passed to thress overloaded methods, which will pick it up? Object FileNotFoundException IOException
FileNotFoundException as it is the most specific
109
Is encapsulation the same as polymorphism?
No
110
Can main use this?
No
111
Is Hashmap a final class?
No
112
What can top level classes not be?
Private | Protected
113
Are throws required for runtimeexceptions?
No
114
If Truck is a subclass of Automobile, is a = t ok?
Yes, no cast is needed
115
If b is a Bat with no relationship,s will b instanceOf Bird compile?
No, incompatible conditional operands between Bird and Bat
116
If original method does not throw a checked exception, what options are left to overriden class to throw?
RuntimeExcpeption | Error
117
If superclass constructor throws an exception, what must the call to the superclass constructor in the subclass do and not do
Specify throws in the signature | Don't surround with try-catch as this would mean try was first statement and not super()
118
If you are not importing a class or the package of the class, what do you need to use to gain access to that class?
The fully qualified name
119
If both classes are in the same package, what is true with regards visibility?
Can be seen and used without importing or extending
120
What is true about interface constants?
They can be accessed by any class that implements the interface
121
Can switch statements be empty?
Yes, but they must contain body braces
122
Are static methods overridden?
No, they are shadowed
123
Can a continue ever be within an if
Yes, if that if is within a for loop
124
What happens if you are trying to access a 1D array using a 2D reference?
It will not compile
125
What throws Errors?
JVM
126
How are objects passed?
Passes value, not reference to object
127
Will this compile? if(x/y)
No, doesn't return a boolean
128
What can an enhanced for loop iterate and not iterate over?
Can iterate over an array or a collection Cannot iterate over a Map
129
Are constructors static or non-static?
Non-static
130
Can abstract classes with a main method compile?
Yes
131
What happens when a SB is passed?
It is mutable and the reference is passed and will be altered accordingly
132
What happens if a class is not in a package
It is created in a default package with no name
133
Can a static method be overridden by a non-static method?
No, and vice-versa
134
What is the order of precedence?
BODMAS Brackets, Orders(powers+sqrts), Division/Multiplication(L-R), Addition/Subtraction(L-R)
135
What throws these? ClassCastException NullPointedException
JVM
136
What throws these? IllegalStateException IllegalArgumentException SecurityException
Application
137
What is happening here? if(b2 != b1 = !b2)
!= happens first flase = !b2 which doesn't equate to boolean hence fails to compile
138
What is the output? ...println(5 + 6 + "");
11
139
What does SB.append do?
Adds to the END
140
What must happen with overridden methods where return type is a primitive?
It must match
141
What can't be used in case statements?
long, float, double and boolean
142
What does ArrayList extend?
java.util.AbstractList
143
How can you access ArrayList?
In random order
144
Do you need to specify the type of ArrayList?
No
145
Does ArrayList implement Random Access?
Yes
146
What does an ArrayList store?
Objects
147
Is Number an object?
Yes
148
What will happen? Integer.parseInt(double/float)
NumberFormatException as it can only parse ints not decimal values
149
What are fields in an interface?
public, abstract and final
150
Can identifier names start with a digit?
No
151
What has a reverse method?
SB
152
Can an interface extend multiple interfaces?
Yes
153
What happens if a catch throws?
It will not be caught by subsequent catches but thrown out to the caller
154
Do default constructors initialise variables?
No
155
Do default constructors call super constructor of super class?
Yes
156
Where can underscores occur in a number?
Only between digits, not before L or F
157
Where can you not specify to add in an ArrayList?
In a position which is not inbetween or immediately after an already populated position
158
Can int and char go into each other?
Yes
159
What will happen here? b1 = (B1) b
Will compile at runtime but fail at runtime as actual object reference by b is not a B1
160
Does ArrayList allow constant time access to all of its elements?
Yes
161
Does Standard JDK docs provide subclasses of ArrayList
Yes
162
What happens to a double that is passed to an Object, Number, Long and Short overloaded methods?
It will be boxed to a Double which extends Number and hence go to Number as it is the most specific
163
What are fields in interfaces?
public, static and final
164
What are methods in interfaces?
public and non-static
165
Will this compile and run? | ( I1 ) tc). m1(
It will as it will point to interface method (which is abstract) and then just call the tc method as is expected
166
What must you make sure of when using ArrayCopy?
The array you are copying to is created to have space for those positions you want filled otherwise ArrayIndexOutOfBoundsException
167
What is true about abstract methods?
They are meant to be overridden
168
Does encapsulation help avoid name clashes?
Yes
169
Does String have an append method?
No
170
What does this do to operands - %
It will evaluate both
171
What consumes less memory - Arrays or ArrayLists?
Arrays
172
What is faster at accessing an element - an array or an arraylist?
Array
173
Which will compile and execute? while (false) if (false)
if
174
What will happen here? | ( AA) a).doStuff(
Will compile fine and point to AA method doStuff() but will not run and will throw a ClassCastException
175
Where do else clauses belong?
To innermost forloop
176
What will happen here? | i == f
i will be promoted to float
177
If a static value in another class is being referred to by the class reference, what is true about the import statment?
Can just import the class using normal import statement
178
If a static value in another class is being referred to directly, what is true about the import statement?
Requires static import
179
Will this compile and execute? | for( ; i
Yes