CS115 important Flashcards

important (11 cards)

1
Q

What is encapsulation in Java?

A

Hiding data by making attributes private and exposing them via public getter and setter methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is inheritance in Java?

A

Allows a subclass to acquire the properties and methods of a superclass using the
‘extends’ keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is polymorphism?

A

Allowing different classes to be treated as instances of the same superclass, with
method behaviour determined at runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens if a static method tries to access a non-static variable?

A

A compilation error occurs. Static methods cannot directly access non-static instance variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is method overriding?

A

Redefining a superclass method in a subclass using the same method signature.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the super keyword do?

A

It refers to the superclass of the current object and is used to access superclass methods or constructors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the operations of a Queue?

A

enqueue (offer), dequeue (poll), peek

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between checked and unchecked exceptions?

A

Checked exceptions are checked at compile time (e.g., IOException); unchecked are checked at runtime (e.g., NullPointerException).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What happens if you override equals() but not hashCode()?

A

Objects that are equal might not behave correctly in hash-based collections like HashMap or HashSet.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a constructor in Java?

A

A special method used to initialize objects; it has the same name as the class and no return type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are generics in Java?

A

They allow classes and methods to operate on objects of various types while providing compile-time type safety.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly