Flashcards

Quick study sessions to strengthen memory and retain key concepts.

Flashcard Study

Java: Variables and Data Types

Front

Why is using double for product prices risky in production code?

double can introduce rounding errors because binary floating-point cannot represent many decimal values exactly. A value like 19.99…

View Card →
Flashcard Study

Java: Variables and Data Types

Front

How should you choose a variable type in beginner Java?

Choose the type that matches the business meaning of the value. A quantity is a whole-number count, a…

View Card →
Flashcard Study

Java: Upcasting and Dynamic Dispatch

Front

Why use abstraction in Java?

Abstraction simplifies complex systems by hiding details. Abstraction allows you to define a class with essential attributes and…

View Card →
Flashcard Study

Java: Upcasting and Dynamic Dispatch

Front

How would you explain an interface’s role in a Java interview?

Interfaces define a contract that implementing classes must follow. An interface in Java specifies methods that a class…

View Card →
Flashcard Study

Java: Upcasting and Dynamic Dispatch

Front

How does compile-time access differ from runtime dispatch?

Compile-time access checks method existence; runtime dispatch executes the method. Compile-time access ensures that the method exists in…

View Card →
Flashcard Study

Java: Upcasting and Dynamic Dispatch

Front

What happens if you call a method not defined in a superclass?

A compile-time error occurs. Frame the concept in practical terms so you can explain it during interview discussion.…

View Card →
Flashcard Study

Java: Upcasting and Dynamic Dispatch

Front

Why is polymorphism beneficial in Java?

Polymorphism enhances flexibility and reusability. Polymorphism allows objects to be treated as instances of their superclass, enabling a…

View Card →
Flashcard Study

Java: Upcasting and Dynamic Dispatch

Front

Why might a ClassCastException occur with upcasting?

ClassCastException occurs if the actual object type doesn't match the cast. When you try to cast an object…

View Card →
Flashcard Study

Java: Upcasting and Dynamic Dispatch

Front

What is dynamic method dispatch?

It is the process where the JVM determines the method to invoke at runtime. Dynamic method dispatch allows…

View Card →
Flashcard Study

Java: Upcasting and Dynamic Dispatch

Front

How can upcasting impact method visibility?

Upcasting can restrict method access to those available in the superclass. When you upcast, you can only call…

View Card →