40 Questions
What is the primary purpose of the main() method in a Java program?
To serve as the entry point for the program
What is the primary purpose of encapsulation in Java?
To hide the sensitive data from external users
What is the purpose of declaring class variables as private?
To hide the sensitive data from external users
What is the default modifier for a class in Java?
Package-private
What happens when a class is declared with the public modifier?
It can be accessed from any class
What is the purpose of get and set methods in Java?
To provide public access to private variables
What is the purpose of the protected modifier in Java?
To provide access to subclasses
What is the correct syntax for accessing a class and its method from another package?
packagename.classname.methodname
What type of relationship exists between a Bank and an Employee?
has-a
When an Employee object is created, what happens to the Date object?
It is automatically referenced and used
What is the type of relationship between a Triangle and a two-dimensional shape?
is-a
What is the main difference between Aggregation and Composition?
Independence of the child object
What happens when a car object is created?
It automatically references the engine object
What is the relationship between a Programmer and an Employee?
is-a
What is the characteristic of objects created from a subclass?
They have their own unique characteristics and also inherit properties of the superclass
What is the purpose of inheritance in object-oriented programming?
To represent an is-a relationship between objects
What is the primary concept of encapsulation in Object-Oriented Programming?
Hiding the data and showing the methods
Which of the following is a feature of Object-Oriented Programming?
Inheritance
What is the process of creating an object from a class?
Instantiation
What is the purpose of a constructor in a class?
To initialize the class
What is the concept of inheritance in Object-Oriented Programming?
Creating a new class from an existing class
What is the main difference between procedural programming and object-oriented programming?
Procedural programming focuses on procedures, while object-oriented programming focuses on objects
What is the concept of abstraction in Object-Oriented Programming?
Hiding the implementation details and showing the functionality
What is the purpose of a package in Object-Oriented Programming?
To group related classes and interfaces together
What is the main characteristic of a one-to-many association?
One object is related to multiple other objects.
What does Java's multiple inheritance implement?
Association
What type of relationship is characterized by a 'part-of' relationship?
Composition
What is the main difference between composition and aggregation?
Composition is a strong association, while aggregation is a weak association.
What is an example of a composition relationship?
A car has an engine.
What type of association is characterized by a 'has-a' relationship?
Aggregation
What is the main characteristic of a many-to-many association?
Multiple objects are related to multiple other objects.
What is the direction of the association in aggregation?
Unidirectional
What is the term for a subclass that inherits properties and behavior from a superclass?
Inheritance
What is the purpose of the super() keyword in a subclass constructor?
To invoke a superclass constructor
What is the correct order of method invocation in a subclass constructor?
Subclass constructor, superclass constructor
What is the result of not using the super() keyword in a subclass constructor?
The superclass constructor will not be invoked
What is the purpose of encapsulation in object-oriented programming?
To hide internal implementation details
What is the correct syntax to invoke a superclass constructor with arguments?
super(arguments)
What is the role of a superclass in inheritance?
To provide a template for the subclass
When must the super() keyword be used in a subclass constructor?
As the first statement of the subclass constructor
Study Notes
Class Definition
- A test class contains the main method, acting as the ignition key.
- The source of this concept is Pearson (Liang).
Encapsulation
- A way to ensure that "sensitive" data is hidden from external users.
- Achieved through:
- Declaring class variables/attributes as private.
- Providing public get and set methods to access and update the value of a private variable.
Packages & Visibility Modifiers
- Specify accessibility or visibility scope of a class and its data fields and methods.
- Default modifier (Package-private or package access):
- Accessible in the same package.
- Public modifier:
- Accessible from any class.
- Private modifier:
- Accessible only within the host class.
- Protected modifier:
- Not mentioned in the text.
Association, Aggregation, and Composition
- Association:
- A relationship between two classes through their objects.
- Types: one-one, one-to-many, and many-to-many.
- Implements Java's multiple inheritance.
- Aggregation:
- A has-a relationship (e.g., a house has a door).
- Unidirectional - one way (e.g., a student has a program).
- Composition:
- A class references objects of other classes as its members.
- May be a part-of relationship (e.g., a car has an engine).
- Strong/strict association (e.g., a car must have an engine to function).
UML - Inheritance
- Subclass extends superclass (e.g., Class Programmer extends Employee).
- The keyword "super" is used to invoke the superclass constructor.
The Keyword super in Inheritance
- "super" invokes the no-arg constructor of its superclass.
- "super(arguments)" invokes the superclass constructor that matches the arguments.
- Must be the first statement of the subclass's constructor.
OOP Concepts
- Objectives:
- Features of OO: encapsulation, polymorphism, abstraction, inheritance, and package.
- Objects, Attributes, and Behaviors of Objects:
- An object is an entity in real-life with distinct states (attributes) and behaviors (methods).
- Association:
- Dependency: child object can exist independently of the parent object.
- Type of relationship: has-a or part-of.
- Type of association: weak or strong.
Inheritance
- A form of is-a relationship (e.g., Programmer is an employee, salesrep is an employee, product manager is an employee).
- Objects created from a subclass have their own unique characteristics but also inherit properties of the superclass.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free