/
AI Flashcards
Save to my account
Sign up
AI Flashcards
Java Core Concepts Flashcards
Study
1
Question
What is a dynamically typed language?
Page 1
Answer
Variables can hold values of different types, with type checking during program execution.
2
Question
What characterizes a statically typed language like Java?
Page 1
Answer
Variables can only hold values of the declared type, checked at compile time.
3
Question
What is the difference between strong and weak typing?
Page 1
Answer
Strong typing enforces strict type rules for safety at compile time; weak typing is more permissive.
4
Question
What is a variable an abstraction of?
Page 1
Answer
A name referring to a location in computer memory.
5
Question
What are the primitive types in Java and their subtype relationships?
Page 1
Answer
byte < short < int < long < float < double; char < int; boolean.
6
Question
What does S <: T mean in subtyping?
Page 1
Answer
S is a subtype of T, allowing code for S to be used safely on T.
7
Question
What is widening type conversion?
Page 1
Answer
Automatic conversion from subtype S to supertype T.
8
Question
What is narrowing type conversion and its risks?
Page 1
Answer
Requires explicit casting from supertype to subtype; risks ClassCastException if incompatible.
9
Question
What is Run Time Type (RTT) versus Compile Time Type (CTT)?
Page 1
Answer
RTT is the actual type at runtime; CTT is the declared type at compile time.
10
Question
How does a range-based for loop work in Java?
Page 1
Answer
Iterates over collections implementing Iterable<U> where U converts to loop variable type T.
11
Question
What is the Liskov Substitution Principle (LSP)?
Page 1
Answer
Subtypes S of T must be substitutable for T without altering program properties.
12
Question
What is abstraction in OOP?
Page 1
Answer
Hiding implementation details to reveal intentions, enabling simple use and code reuse.
13
Question
What is the abstraction barrier?
Page 1
Answer
Separation between implementer (internal details) and client (external interface).
14
Question
What is encapsulation in OOP?
Page 1
Answer
Bundling data and methods within a class, using private fields and public methods.
15
Question
What role do constructors play in encapsulation?
Page 1
Answer
Initialize private fields during object creation, controlling access to internal state.
16
Question
What is the 'this' keyword in Java?
Page 1
Answer
Refers to the current object instance.
17
Question
What is the default value for uninitialized reference variables?
Page 1
Answer
null.
18
Question
What is the 'Tell, Don’t Ask' principle?
Page 1
Answer
Instruct objects to perform actions rather than querying and manipulating externally.
19
Question
What are static methods and fields?
Page 1
Answer
Associated with the class, not instances; declared with 'static' keyword.
20
Question
What is the main method signature in Java?
Page 1
Answer
public static void main(String[] args).
21
Question
What is a 'has-a' relationship in OOP?
Page 1
Answer
Composition, where one class contains another as a field.
22
Question
What is an 'is-a' relationship?
Page 1
Answer
Inheritance using 'extends' for subtyping.
23
Question
What does every Java class implicitly inherit from?
Page 1
Answer
The Object class, root of the hierarchy.
24
Question
How is the superclass constructor called?
Page 1
Answer
Using 'super(arguments)' in the subclass constructor.
25
Question
Why avoid overusing inheritance?
Page 2
Answer
Ensure it preserves subtyping meaning; prefer composition when possible.
26
Question
What is polymorphism?
Page 2
Answer
Ability to change code behavior without modifying existing code, via dynamic binding.
27
Question
What is dynamic binding?
Page 2
Answer
Method invocation determined at runtime based on object type.
28
Question
What is method overloading?
Page 2
Answer
Static polymorphism: same name, different parameters (types/number/order).
29
Question
What is method overriding?
Page 2
Answer
Dynamic polymorphism: same signature in subclass as in superclass.
30
Question
What comprises a method signature?
Page 2
Answer
Method name, parameter types, number, and order; excludes return type and exceptions.