Object-Oriented Programming Fundamentals

AuthenticPeace avatar
AuthenticPeace
·
·
Download

Start Quiz

Study Flashcards

14 Questions

What is the primary purpose of encapsulation in object-oriented programming?

To hide data and behavior from outside the class

What is the term for when a child class provides a different implementation of a method with the same signature as a parent class?

Method overriding

What is the primary purpose of using synchronized methods and blocks in multithreading?

To ensure thread safety

What is the term for a separate flow of execution within a program?

Thread

What is the term for an unordered collection of unique elements?

Set

What is the term for when two or more threads are blocked, waiting for each other to release a resource?

Deadlock

What is the term for a class that can be inherited by only one child class?

Single inheritance class

What is the term for a blueprint for creating objects?

Class

Which collection interface provides a way to iterate over a collection?

Iterable

What type of exception must be explicitly handled or declared?

Checked exception

What is the purpose of a finally block in exception handling?

For resource cleanup and releasing locks

Which implementation of List is a linked list-based implementation?

LinkedList

What is the purpose of the throws clause in a method declaration?

To declare that a method may throw an exception

Which collection class is a hash-based implementation of Map?

HashMap

Study Notes

Object-Oriented Programming (OOP)

  • Class and Object:
    • A class is a blueprint for creating objects.
    • An object is an instance of a class.
  • Inheritance:
    • A child class inherits properties and behavior from a parent class.
    • Single inheritance: a child class can inherit from one parent class.
    • Multilevel inheritance: a child class can inherit from a parent class that itself inherits from another parent class.
  • Polymorphism:
    • Method overriding: a child class provides a different implementation of a method with the same signature as a parent class.
    • Method overloading: multiple methods with the same name but different parameters.
  • Abstraction:
    • Abstract classes and interfaces define a blueprint for other classes to follow.
    • Abstract methods have no implementation and must be implemented by subclasses.
  • Encapsulation:
    • Data hiding: variables and methods are encapsulated within a class, making them inaccessible from outside.
    • Access modifiers (public, private, protected) control access to class members.

Multithreading

  • Threads:
    • A thread is a separate flow of execution within a program.
    • Threads can run concurrently, improving program responsiveness and performance.
  • Thread Creation:
    • Extend the Thread class or implement the Runnable interface.
    • Use the start() method to start a thread.
  • Thread Synchronization:
    • Synchronized methods and blocks ensure thread safety by locking access to shared resources.
    • wait() and notify() methods allow threads to communicate and coordinate.
  • Deadlocks and Starvation:
    • Deadlocks: two or more threads are blocked, waiting for each other to release a resource.
    • Starvation: a thread is unable to access a resource due to other threads holding onto it.

Collections

  • Types of Collections:
    • List: an ordered collection of elements (e.g., ArrayList, LinkedList).
    • Set: an unordered collection of unique elements (e.g., HashSet, TreeSet).
    • Map: a collection of key-value pairs (e.g., HashMap, TreeMap).
  • Collection Interfaces:
    • Iterable: provides a way to iterate over a collection.
    • Collection: provides basic operations (e.g., add, remove, contains) for a collection.
    • List, Set, and Map interfaces extend Collection and provide additional methods.
  • Common Collection Classes:
    • ArrayList: a resizable array-based implementation of List.
    • LinkedList: a linked list-based implementation of List.
    • HashMap: a hash-based implementation of Map.

Exception Handling

  • Try-Catch Blocks:
    • try block: contains code that may throw an exception.
    • catch block: catches and handles an exception.
  • Exception Types:
    • Checked exceptions: must be explicitly handled or declared (e.g., IOException).
    • Unchecked exceptions: do not need to be explicitly handled or declared (e.g., NullPointerException).
  • Throwing and Rethrowing:
    • throw statement: throws an exception explicitly.
    • throws clause: declares that a method may throw an exception.
    • Rethrowing: re-throwing an exception from a catch block to propagate it up the call stack.
  • finally Block:
    • A finally block is executed regardless of whether an exception is thrown or not.
    • Used for resource cleanup and releasing locks.

Object-Oriented Programming (OOP)

  • A class is a blueprint for creating objects.
  • An object is an instance of a class.

Inheritance

  • A child class inherits properties and behavior from a parent class.
  • Single inheritance: a child class can inherit from one parent class.
  • Multilevel inheritance: a child class can inherit from a parent class that itself inherits from another parent class.

Polymorphism

  • Method overriding: a child class provides a different implementation of a method with the same signature as a parent class.
  • Method overloading: multiple methods with the same name but different parameters.

Abstraction

  • Abstract classes and interfaces define a blueprint for other classes to follow.
  • Abstract methods have no implementation and must be implemented by subclasses.

Encapsulation

  • Data hiding: variables and methods are encapsulated within a class, making them inaccessible from outside.
  • Access modifiers (public, private, protected) control access to class members.

Multithreading

  • A thread is a separate flow of execution within a program.
  • Threads can run concurrently, improving program responsiveness and performance.

Thread Creation

  • Extend the Thread class or implement the Runnable interface.
  • Use the start() method to start a thread.

Thread Synchronization

  • Synchronized methods and blocks ensure thread safety by locking access to shared resources.
  • wait() and notify() methods allow threads to communicate and coordinate.

Deadlocks and Starvation

  • Deadlocks: two or more threads are blocked, waiting for each other to release a resource.
  • Starvation: a thread is unable to access a resource due to other threads holding onto it.

Collections

  • List: an ordered collection of elements (e.g., ArrayList, LinkedList).
  • Set: an unordered collection of unique elements (e.g., HashSet, TreeSet).
  • Map: a collection of key-value pairs (e.g., HashMap, TreeMap).

Collection Interfaces

  • Iterable: provides a way to iterate over a collection.
  • Collection: provides basic operations (e.g., add, remove, contains) for a collection.
  • List, Set, and Map interfaces extend Collection and provide additional methods.

Common Collection Classes

  • ArrayList: a resizable array-based implementation of List.
  • LinkedList: a linked list-based implementation of List.
  • HashMap: a hash-based implementation of Map.

Exception Handling

  • try block: contains code that may throw an exception.
  • catch block: catches and handles an exception.

Exception Types

  • Checked exceptions: must be explicitly handled or declared (e.g., IOException).
  • Unchecked exceptions: do not need to be explicitly handled or declared (e.g., NullPointerException).

Throwing and Rethrowing

  • throw statement: throws an exception explicitly.
  • throws clause: declares that a method may throw an exception.
  • Rethrowing: re-throwing an exception from a catch block to propagate it up the call stack.

finally Block

  • A finally block is executed regardless of whether an exception is thrown or not.
  • Used for resource cleanup and releasing locks.

This quiz covers the basics of Object-Oriented Programming, including classes, objects, inheritance, and polymorphism. Test your understanding of these OOP concepts.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Use Quizgecko on...
Browser
Browser