0. OOP Flashcards
(57 cards)
What is Object Oriented Programming (OOP)?
Object Oriented Programming (OOP) is a programming paradigm based on the concept of ‘objects’, which can contain data in the form of fields and code in the form of procedures or methods.
What are the four main principles of OOP?
The four main principles of OOP are Encapsulation, Abstraction, Inheritance, and Polymorphism.
What is encapsulation in OOP?
Encapsulation is the principle of bundling the data (attributes) and methods (functions) that operate on the data into a single unit, or class, and restricting access to some of the object’s components.
True or False: In Java, encapsulation is achieved using access modifiers.
True.
What is abstraction in OOP?
Abstraction is the principle of hiding the complex implementation details of a system and exposing only the necessary features to the user.
How does inheritance work in Java?
Inheritance allows a new class (subclass) to inherit properties and methods from an existing class (superclass), enabling code reusability and the creation of hierarchical relationships between classes.
Fill in the blank: In Java, a class that is inherited from is called a __________.
superclass.
What is polymorphism in OOP?
Polymorphism is the ability of different classes to be treated as instances of the same class through a common interface, allowing methods to perform differently based on the object that it is acting upon.
What is a class in Java?
A class in Java is a blueprint for creating objects that defines a set of attributes and methods that the created objects will have.
What is an object in Java?
An object is an instance of a class, containing specific values for the attributes defined in the class.
What are access modifiers in Java?
Access modifiers are keywords that set the accessibility levels for classes, methods, and variables. The main access modifiers in Java are public, private, protected, and default.
What does the ‘private’ access modifier do?
‘Private’ restricts the visibility of a class member to within the class itself, making it inaccessible from outside the class.
What is a constructor in Java?
A constructor is a special method used to initialize objects. It has the same name as the class and does not have a return type.
True or False: A Java class can have multiple constructors.
True.
What is method overloading in Java?
Method overloading is a feature that allows a class to have more than one method with the same name but different parameters (different type or number of parameters).
What is method overriding in Java?
Method overriding occurs when a subclass provides a specific implementation of a method that is already defined in its superclass.
What is the purpose of the ‘super’ keyword?
The ‘super’ keyword is used to refer to the superclass of the current object and can be used to call superclass methods and constructors.
What is an interface in Java?
An interface in Java is a reference type similar to a class that can contain only constants, method signatures, default methods, static methods, and nested types. Interfaces cannot contain instance fields or constructors.
Fill in the blank: A class can implement multiple __________ in Java.
interfaces.
What is an abstract class in Java?
An abstract class is a class that cannot be instantiated and may contain abstract methods, which are methods without a body that must be implemented by subclasses.
True or False: An abstract class can have both abstract and concrete methods.
True.
What is the difference between an interface and an abstract class?
An interface can only contain method signatures and constants, whereas an abstract class can contain both abstract methods and concrete methods, along with instance variables.
What is a package in Java?
A package in Java is a namespace that organizes a set of related classes and interfaces, helping to avoid naming conflicts and controlling access.
What is the main purpose of the Java Collections Framework?
The Java Collections Framework provides a set of classes and interfaces for storing and manipulating groups of data as a single unit, offering efficient ways to handle collections of objects.