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
Q

What will this add?

ArrayList addAll(1,1)

A

Adds from point 1 to 1 exclusive hence adds nothing

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

Do switch statements need defaults?

A

No

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

Is an empty switch blocks valid?

A

Yes

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

What access modifiers can top level classes not have?

A

private

protected

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

Which has a reverse method - String or StringBuilder

A

StringBuilder

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

Can constructors throw exceptions?

A

Yes

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

What does prefix 0b/0B mean?

A

Binary

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

Is appends a StringBuilder, StringBuffer or String method?

A

StringBuilder and StringBuffer

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

Is intern a StringBuilder, StringBuffer or String method?

A

String

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

Can charAt take a char value?

A

Yes, but it will promote to an int

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

What must happen to finals?

A
  • must be initialized in init blocks

- initialized in every constructor.

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

Can overriding methods declare no exceptions?

A

Yes, they can opt to declare no exceptions

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

Can case statements in a switch be the same value?

A

No, they cannot be the same value

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

Are these two the same?

case 1000000
case 1_000_000

A

Yes, and that is illegal

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

Can arrays be created with zero length?

A

Yes

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

What must happen to override methods?

A

Access modifiers must be less or equally as restrictive and return types must match

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

Can static and non-static methods have the same name?

A

No, each method must have a unique name

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

What is true about wrapper objects?

A

They are always immutable

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

What can variables not be declared as?

A

abstract or native

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

What can varargs (…) take?

A

Nothing to the largest array

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

Is $ an operator?

A

No

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

Is ~ an operator?

A

Yes

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

What must happen to a method signature for a method that isn’t suppose to return anything

A

It must specify void

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

Will this work?

for(;;)

A

Yes, it’s an infinite loop but it is valid

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

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?

A

No, because it started as null, it will be different to the other string

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

Can a constructor be final?

A

No

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

Can static methods also be abstract

A

No

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

If original method does not throw a checked exception, what can an overridden method throw?

A

Runtime Exception
Error

Not a checked exception

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

How can char variables be assigned to shorts?

A

With explicit casting

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

What is true about chars and shorts going into each other?

A

They require specific casting

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

What is true for all member fields?

A

They are auto-initialised to default values - 0, 0.0, null, etc

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

What is true for overloaded methods where the caller method parameters could fit into more than one overloaded method?

A

It will call the most specific one

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

Which one is allowed?

int a = b = c = 100;
int a, b, c; a = b =c = 100;

A

The second, as the values are initialised first beforehand

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

Does Stringbuilder have a delete method?

A

Yes

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

Does StringBuilder have a setCapacity or ensureCapacity method?

A

ensureCapacity

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

Are floating point suffixes used on binary numbers?

A

No

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

Are L suffixes used on binary numbers?

A

Yes they can be

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

Is this valid?

String String = “String”;

A

Yes, perfectly valie

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

What is the outcome?

int i =0;
ia[i] = i = 30;

A

is[0] = 30

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

What happens when char is auto-initialised as an instance variable?

A

It gets set to 0 which is an empty space

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

Is args ever NULL

A

No, it will always have a length of at least 0

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

Is this valid?

for (final Object o: a)

A

Yes, final is the only modifier allowed in this enhance for loop statement

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

Can you specify the visibility of local variables?

A

No

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

Can if statements have empty - just colon - statements?

A

Yes

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

Can synchronised ever be applied to a class?

A

No

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

Can synchronised ever be applied to a variable?

A

No

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

Can synchronised ever be applied to a method or block?

A

Yes, synchronised can only be applied to a method or block

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

Can a constructor be overridden?

A

No

73
Q

What does the equals method of the object do?

A

It checks to see whether the object references are pointing to the same objects

74
Q

What will happen if a public class is run without the special main method?

A

It will throw a runtime error for java.lang.NoSuchMethodError

75
Q

Can you have a switch statement of type int and a case statement of type chat?

A

Yes

76
Q

What must the right side of the instanceOf always be?

A

An object

77
Q

What must happen with the main and void in the main method signature?

A

They must always be together

78
Q

What is happening here?

int i = 1______3;
int p = 1_3;

A

Both will equal 13

79
Q

Will finally still get executed if System.exit(0) is used within the try?

A

No, it is the one time that the final block will not get executed

80
Q

What are exceptions used for?

A

To determine what to do when something goes wrong

Used also for logging

81
Q

Can you instantiate or increment inside a while clause?

A

No

82
Q

What will happen here and is it valid?

for(int i = 0; ; i++) break;

A

It is valid

It will execute once and then stop

83
Q

What are the possible outcomes of charAt() if it needs to throw due to an incorrect value

A

More than likely StringIndexOutOfBounds exception, but could also throw IndexOutOfBounds exception so can’t be sure

84
Q

What happens if you throw without a catch block or throws in the method signature?

A

It will fail to compile

85
Q

What is java.lang.SecurityException?

A

A runtime exception

86
Q

Is args ever null?

A

No

87
Q

Does String have a concat method?

A

Yes

88
Q

What must happen if the reference method throws an exception but the object method does not?

A

You still must have a try-catch or throws in place at compile time for obvious reasons

89
Q

How do you import static members of a class?

A

Using static imports statements

90
Q

Can the main method be declared final?

A

Yes

91
Q

Can you use the keyword this on static members?

A

Yes but it is unnecessary

92
Q

Will this compile?

double x = 10, double y;

A

No, the comma is the issue here between two primitive declarations

93
Q

What must happen with final variables?

A

They must be initialised by init blocks or by every constructor

94
Q

What will happen in this String method

.substring(9,15)

A

Will take from char 9 until character 14, not incorporating character 15

95
Q

What is true for floats?

A

Always have an f suffix

96
Q

What does the replace method on a String do if there is a change?

A

Returns a new object

97
Q

What does the repalce method of a String do if there is no change?

A

Returns the same object

98
Q

What must the left side of an operand be?

A

An object, not a primative

99
Q

What will happen here?

int x2 = x1–;

A

x2 is assigned the value of x1 and then x1 is decremented

100
Q

What will happen here?

if (a = b)…

A

Will evaluate to true and be grand for an if statement

101
Q

Can booleans, longs, floats and doubles be used in switch statements?

A

No

102
Q

Can a char be assigned a int value implicitly?

A

No, implicit narrowing will not work

103
Q

What is the difference between & and &&?

A

& can have both integral as well as boolean operators, whereas && can only have boolean operators

104
Q

If b and d are different types, will b == d compile?

A

No

105
Q

Is this valid?

block : { beak block; }

A

Yes

106
Q

Is this valid?

{ { } }

A

Yes, valid compound statement

107
Q

Can continue occur within a switch statement?

A

No

108
Q

If null is passed to thress overloaded methods, which will pick it up?

Object
FileNotFoundException
IOException

A

FileNotFoundException as it is the most specific

109
Q

Is encapsulation the same as polymorphism?

A

No

110
Q

Can main use this?

A

No

111
Q

Is Hashmap a final class?

A

No

112
Q

What can top level classes not be?

A

Private

Protected

113
Q

Are throws required for runtimeexceptions?

A

No

114
Q

If Truck is a subclass of Automobile, is a = t ok?

A

Yes, no cast is needed

115
Q

If b is a Bat with no relationship,s will b instanceOf Bird compile?

A

No, incompatible conditional operands between Bird and Bat

116
Q

If original method does not throw a checked exception, what options are left to overriden class to throw?

A

RuntimeExcpeption

Error

117
Q

If superclass constructor throws an exception, what must the call to the superclass constructor in the subclass do and not do

A

Specify throws in the signature

Don’t surround with try-catch as this would mean try was first statement and not super()

118
Q

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?

A

The fully qualified name

119
Q

If both classes are in the same package, what is true with regards visibility?

A

Can be seen and used without importing or extending

120
Q

What is true about interface constants?

A

They can be accessed by any class that implements the interface

121
Q

Can switch statements be empty?

A

Yes, but they must contain body braces

122
Q

Are static methods overridden?

A

No, they are shadowed

123
Q

Can a continue ever be within an if

A

Yes, if that if is within a for loop

124
Q

What happens if you are trying to access a 1D array using a 2D reference?

A

It will not compile

125
Q

What throws Errors?

A

JVM

126
Q

How are objects passed?

A

Passes value, not reference to object

127
Q

Will this compile?

if(x/y)

A

No, doesn’t return a boolean

128
Q

What can an enhanced for loop iterate and not iterate over?

A

Can iterate over an array or a collection

Cannot iterate over a Map

129
Q

Are constructors static or non-static?

A

Non-static

130
Q

Can abstract classes with a main method compile?

A

Yes

131
Q

What happens when a SB is passed?

A

It is mutable and the reference is passed and will be altered accordingly

132
Q

What happens if a class is not in a package

A

It is created in a default package with no name

133
Q

Can a static method be overridden by a non-static method?

A

No, and vice-versa

134
Q

What is the order of precedence?

A

BODMAS

Brackets, Orders(powers+sqrts), Division/Multiplication(L-R), Addition/Subtraction(L-R)

135
Q

What throws these?

ClassCastException
NullPointedException

A

JVM

136
Q

What throws these?

IllegalStateException
IllegalArgumentException
SecurityException

A

Application

137
Q

What is happening here?

if(b2 != b1 = !b2)

A

!= happens first

flase = !b2 which doesn’t equate to boolean hence fails to compile

138
Q

What is the output?

…println(5 + 6 + “”);

A

11

139
Q

What does SB.append do?

A

Adds to the END

140
Q

What must happen with overridden methods where return type is a primitive?

A

It must match

141
Q

What can’t be used in case statements?

A

long, float, double and boolean

142
Q

What does ArrayList extend?

A

java.util.AbstractList

143
Q

How can you access ArrayList?

A

In random order

144
Q

Do you need to specify the type of ArrayList?

A

No

145
Q

Does ArrayList implement Random Access?

A

Yes

146
Q

What does an ArrayList store?

A

Objects

147
Q

Is Number an object?

A

Yes

148
Q

What will happen?

Integer.parseInt(double/float)

A

NumberFormatException as it can only parse ints not decimal values

149
Q

What are fields in an interface?

A

public, abstract and final

150
Q

Can identifier names start with a digit?

A

No

151
Q

What has a reverse method?

A

SB

152
Q

Can an interface extend multiple interfaces?

A

Yes

153
Q

What happens if a catch throws?

A

It will not be caught by subsequent catches but thrown out to the caller

154
Q

Do default constructors initialise variables?

A

No

155
Q

Do default constructors call super constructor of super class?

A

Yes

156
Q

Where can underscores occur in a number?

A

Only between digits, not before L or F

157
Q

Where can you not specify to add in an ArrayList?

A

In a position which is not inbetween or immediately after an already populated position

158
Q

Can int and char go into each other?

A

Yes

159
Q

What will happen here?

b1 = (B1) b

A

Will compile at runtime but fail at runtime as actual object reference by b is not a B1

160
Q

Does ArrayList allow constant time access to all of its elements?

A

Yes

161
Q

Does Standard JDK docs provide subclasses of ArrayList

A

Yes

162
Q

What happens to a double that is passed to an Object, Number, Long and Short overloaded methods?

A

It will be boxed to a Double which extends Number and hence go to Number as it is the most specific

163
Q

What are fields in interfaces?

A

public, static and final

164
Q

What are methods in interfaces?

A

public and non-static

165
Q

Will this compile and run?

( I1 ) tc). m1(

A

It will as it will point to interface method (which is abstract) and then just call the tc method as is expected

166
Q

What must you make sure of when using ArrayCopy?

A

The array you are copying to is created to have space for those positions you want filled otherwise ArrayIndexOutOfBoundsException

167
Q

What is true about abstract methods?

A

They are meant to be overridden

168
Q

Does encapsulation help avoid name clashes?

A

Yes

169
Q

Does String have an append method?

A

No

170
Q

What does this do to operands - %

A

It will evaluate both

171
Q

What consumes less memory - Arrays or ArrayLists?

A

Arrays

172
Q

What is faster at accessing an element - an array or an arraylist?

A

Array

173
Q

Which will compile and execute?

while (false)
if (false)

A

if

174
Q

What will happen here?

( AA) a).doStuff(

A

Will compile fine and point to AA method doStuff() but will not run and will throw a ClassCastException

175
Q

Where do else clauses belong?

A

To innermost forloop

176
Q

What will happen here?

i == f

A

i will be promoted to float

177
Q

If a static value in another class is being referred to by the class reference, what is true about the import statment?

A

Can just import the class using normal import statement

178
Q

If a static value in another class is being referred to directly, what is true about the import statement?

A

Requires static import

179
Q

Will this compile and execute?

for( ; i

A

Yes