NEW SWE Core 1 (Java) Flashcards

Key Java Concepts: Encapsulation, Inheritance, Polymorphism, Abstraction, and SOLID Principles

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

What is encapsulation in Java?

A

Encapsulation is the concept of wrapping data and methods that operate on the data within a single unit, usually a class, and restricting access to some components.

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

True or False: Inheritance allows a class to inherit properties and methods from another class.

A

True

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

Fill in the blank: Polymorphism allows methods to do different things based on the object it is acting upon, enabling multiple forms of _______.

A

behavior

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

What is abstraction in Java?

A

Abstraction is the concept of hiding the complex implementation details and showing only the essential features of the object.

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

Which SOLID principle focuses on ensuring that a class should have only one reason to change?

A

Single Responsibility Principle

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

What is the main benefit of using encapsulation?

A

The main benefit is improved data security and integrity by restricting direct access to class members.

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

Multiple Choice: Which of the following is NOT a type of inheritance in Java? A) Single B) Multiple C) Multilevel D) Hierarchical

A

B) Multiple

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

What do you call a method that can operate on objects of different classes?

A

Polymorphic method

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

True or False: Abstraction can be achieved using abstract classes and interfaces.

A

True

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

Fill in the blank: The _______ principle states that classes should be open for extension but closed for modification.

A

Open/Closed

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

What is the difference between compile-time and runtime polymorphism?

A

Compile-time polymorphism is achieved through method overloading, while runtime polymorphism is achieved through method overriding.

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

Which keyword is used to implement inheritance in Java?

A

extends

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

True or False: The Liskov Substitution Principle states that objects of a superclass should be replaceable with objects of a subclass without affecting the correctness of the program.

A

True

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

What is the primary purpose of the Interface in Java?

A

To define a contract that classes can implement, allowing abstraction and multiple inheritance.

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

Multiple Choice: Which of the following is an example of encapsulation? A) Using private variables B) Using public methods C) Both A and B

A

C) Both A and B

17
Q

What is method overriding?

A

Method overriding occurs when a subclass provides a specific implementation of a method that is already defined in its superclass.

18
Q

Fill in the blank: The _______ principle emphasizes that classes should not be forced to implement interfaces they do not use.

A

Interface Segregation

19
Q

What is the purpose of the Dependency Inversion Principle?

A

To ensure that high-level modules are not dependent on low-level modules, but both should depend on abstractions.

20
Q

True or False: Inheritance can lead to a tight coupling between classes.

21
Q

What is the role of constructors in encapsulation?

A

Constructors are used to initialize the object’s state and can enforce encapsulation by restricting direct access to the object’s variables.