General Flashcards
All Java code is written inside…
Classes
Where can code blocks be used?
Anywhere a single statement is expected
What are the 3 different types of Java comments?
- Single-line comments
//
- Multi-line comments
/* */
- Documentation comments
/** */
What are the 8 Java primitive types?
- byte
- short
- int
- long
- float
- double
- char
- boolean
- How many bits are in an
int
andlong
? - How many bits are in a
float
anddouble
? - How many bits are in a
char
?
- 32 bits (4 bytes) and 64 bits (8 bytes)
- 32 bits (4 bytes) and 64 bits (8 bytes)
- 16 bits (2 bytes)
- What is the default integer type?
- What is the default floating-point type?
- int
- double
Give an example of a long literal
100L
True or False
true == 1 false == 0
False. There are no “truthy” or “falsy” values in Java
True or False
Does a code block define a scope?
Yes. variables declared inside a code block will no longer be reachable once the block is exited
True or False:
Inner scopes have access to enclosing outer scopes, but outer scopes do not have access to inner scopes.
True
- What are the 6 relatinoal operators?
- What type do they evaluate to?
- > , >=, <, <=, ==, !=
- booleans
Is it possible to have multiple methods with the same name inside the same class?
Yes, but only if the methods have different parameter types, number of parameters, or order of parameters. Return types are not considered for method overloading
What are the 5 ways to use “final”?
- Classes
- Properties
- Methods
- Method parameters
- Local variables
True or False
Does an inner class definition have access to the private members of its enclosing classes?
Yes
- If a method defines normal and variable parameters, where on the parameter list should varargs be used?
- Can a method use multiple varargs?
- Varargs should be used at the end of the method parameter list
- No. A method cannot define multiple vargargs
If a subclass object is assigned to a superclass type, and the subclass object overrides the methods of the superclass, which methods will be called?
If a subclass object is assigned to a superclass type, and the subclass object overrides the methods of the superclass, the methods of the subclass object will be called
What are the 2 ways to use super?
- To access the members of an enclosing class
- To call a superclass constructor
When a subclass is instantiated, are all superclass constructors called?
Yes