NEW SWE Core 1 (Java) Flashcards
Key Java Concepts: Encapsulation, Inheritance, Polymorphism, Abstraction, and SOLID Principles
What is encapsulation in Java?
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.
True or False: Inheritance allows a class to inherit properties and methods from another class.
True
Fill in the blank: Polymorphism allows methods to do different things based on the object it is acting upon, enabling multiple forms of _______.
behavior
What is abstraction in Java?
Abstraction is the concept of hiding the complex implementation details and showing only the essential features of the object.
Which SOLID principle focuses on ensuring that a class should have only one reason to change?
Single Responsibility Principle
What is the main benefit of using encapsulation?
The main benefit is improved data security and integrity by restricting direct access to class members.
Multiple Choice: Which of the following is NOT a type of inheritance in Java? A) Single B) Multiple C) Multilevel D) Hierarchical
B) Multiple
What do you call a method that can operate on objects of different classes?
Polymorphic method
True or False: Abstraction can be achieved using abstract classes and interfaces.
True
Fill in the blank: The _______ principle states that classes should be open for extension but closed for modification.
Open/Closed
What is the difference between compile-time and runtime polymorphism?
Compile-time polymorphism is achieved through method overloading, while runtime polymorphism is achieved through method overriding.
Which keyword is used to implement inheritance in Java?
extends
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.
True
What is the primary purpose of the Interface in Java?
To define a contract that classes can implement, allowing abstraction and multiple inheritance.
Multiple Choice: Which of the following is an example of encapsulation? A) Using private variables B) Using public methods C) Both A and B
C) Both A and B
What is method overriding?
Method overriding occurs when a subclass provides a specific implementation of a method that is already defined in its superclass.
Fill in the blank: The _______ principle emphasizes that classes should not be forced to implement interfaces they do not use.
Interface Segregation
What is the purpose of the Dependency Inversion Principle?
To ensure that high-level modules are not dependent on low-level modules, but both should depend on abstractions.
True or False: Inheritance can lead to a tight coupling between classes.
True
What is the role of constructors in encapsulation?
Constructors are used to initialize the object’s state and can enforce encapsulation by restricting direct access to the object’s variables.