Java Questions 22: Constructors and Data Types
- Why can't a constructor be marked static?
Answer:
Constructors cannot be marked static because they are associated with instantiation.
- Why can't a constructor be marked final?
Answer:
Constructors are not inherited so they can't be overridden, so what is the use of having a final constructor.
-
What is the purpose of a reference variable?
Answer:
The purpose of a reference variable is to refer to or acces an object.
-
What type can a reference variable refer to?
Answer:
A reference variable can be used to refer to any object of the declared type, or of a subtype of the declared type (a compatible type).
-
For integer types, what is the sequence from small to large?
Answer:
- byte - 8
- short - 16
- int -32
- long -64
-
How can you remember that doubles are larger than floats?
Answer:
A double is twice the number of bits as a float (32 X 2 = 64) bits.
[byte - 8, short - 16, int -32, long - 64, float -32, double -64]
-
What does it mean when datatypes are signed?
Answer:
Signed means the datatypes are positive or negative.
-
What do the data types long and double have in common?
Answer:
Long and double are both 64 bit.
-
What are the characteristics of the
char
data type?
Answer:
The char type contains a single, 16-bit Unicode character.
-
Which two keywords are not allowed to preceed a constructor?
Answer:
Constructors cannot be preceeded by the keywords 1) static or 2) final.