CS115 important Flashcards
important (11 cards)
What is encapsulation in Java?
Hiding data by making attributes private and exposing them via public getter and setter methods.
What is inheritance in Java?
Allows a subclass to acquire the properties and methods of a superclass using the
‘extends’ keyword
What is polymorphism?
Allowing different classes to be treated as instances of the same superclass, with
method behaviour determined at runtime.
What happens if a static method tries to access a non-static variable?
A compilation error occurs. Static methods cannot directly access non-static instance variables.
What is method overriding?
Redefining a superclass method in a subclass using the same method signature.
What does the super keyword do?
It refers to the superclass of the current object and is used to access superclass methods or constructors.
What are the operations of a Queue?
enqueue (offer), dequeue (poll), peek
What is the difference between checked and unchecked exceptions?
Checked exceptions are checked at compile time (e.g., IOException); unchecked are checked at runtime (e.g., NullPointerException).
What happens if you override equals() but not hashCode()?
Objects that are equal might not behave correctly in hash-based collections like HashMap or HashSet.
What is a constructor in Java?
A special method used to initialize objects; it has the same name as the class and no return type.
What are generics in Java?
They allow classes and methods to operate on objects of various types while providing compile-time type safety.