CST8132 OOP Lecture Notes
30 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is abstraction in Java?

  • Hiding implementation details from the user (correct)
  • Showing implementation details to the user
  • Displaying the functionality to the user
  • Providing the implementation details to the user

What is the relationship between a subclass and a superclass?

  • Composition
  • Polymorphism
  • Inheritance (correct)
  • Abstraction

What is achieved through abstract classes and interfaces in Java?

  • Abstraction (correct)
  • Inheritance
  • Polymorphism
  • Encapsulation

What is the purpose of abstraction in Java?

<p>To hide implementation details from the user (B)</p> Signup and view all the answers

What is inherited from a superclass to a subclass?

<p>Methods and properties (B)</p> Signup and view all the answers

What is the concept that relates to hiding implementation details in Java?

<p>Abstraction (D)</p> Signup and view all the answers

What is the term for a class that cannot be instantiated?

<p>Abstract class (D)</p> Signup and view all the answers

What is the term for a collection of abstract methods?

<p>Interface (B)</p> Signup and view all the answers

What is the purpose of inheritance in Java?

<p>To inherit properties and methods (B)</p> Signup and view all the answers

What is the relationship between a subclass and a superclass in terms of inheritance?

<p>Many-to-one (A)</p> Signup and view all the answers

What happens when a class includes abstract methods?

<p>The class must be declared abstract. (A)</p> Signup and view all the answers

What is the purpose of an abstract class?

<p>To declare a class that cannot be instantiated. (A)</p> Signup and view all the answers

Can an abstract class be instantiated?

<p>No, it cannot be instantiated. (D)</p> Signup and view all the answers

What happens if a subclass does not provide implementations for all abstract methods?

<p>The subclass will be abstract. (D)</p> Signup and view all the answers

What is the main difference between an abstract class and an interface?

<p>An abstract class has methods with implementation, an interface does not. (D)</p> Signup and view all the answers

What is the purpose of an interface?

<p>To group related methods with empty bodies. (D)</p> Signup and view all the answers

Can an interface have properties?

<p>Yes, an interface can have public static final properties. (C)</p> Signup and view all the answers

What is an example of a situation where an abstract class could be made into an interface?

<p>When an abstract class has nothing other than public static final properties and abstract methods. (C)</p> Signup and view all the answers

What is the purpose of the 'Shape' abstract class in the example?

<p>To provide a blueprint for other shape classes. (A)</p> Signup and view all the answers

How do you use an abstract class?

<p>You have to inherit it from another class and provide implementations to the abstract methods. (C)</p> Signup and view all the answers

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

<p>To define a set of method signatures and their return values (D)</p> Signup and view all the answers

What is the difference between an interface and an abstract class?

<p>An abstract class can have non-abstract methods, while an interface cannot (C)</p> Signup and view all the answers

How do you create an array in Java?

<p>String studentName[] = new String; (A)</p> Signup and view all the answers

What is the difference between creating an array and an ArrayList in Java?

<p>Arrays are static, while ArrayLists are dynamic (C)</p> Signup and view all the answers

How do you add an element to the beginning of an ArrayList in Java?

<p>studentNames.add(0, &quot;John&quot;); (A)</p> Signup and view all the answers

What is the purpose of the implements keyword in Java?

<p>To implement an interface (D)</p> Signup and view all the answers

What is the term for the combination of a method name, number and type of parameters?

<p>Method signature (A)</p> Signup and view all the answers

What is the primary difference between an array and an ArrayList in terms of memory allocation?

<p>Arrays are stored on the stack, while ArrayLists are stored on the heap (B)</p> Signup and view all the answers

What is the purpose of an interface in terms of object-oriented programming?

<p>To define a set of method signatures and their return values (A)</p> Signup and view all the answers

How do you print the elements of an ArrayList in Java?

<p>Using a for-each loop (B)</p> Signup and view all the answers

Study Notes

OOP Concepts

  • Week 5B topics include Abstract Classes, Inheritance, Override, Customization, Interfaces, Contracts in OO, UML, and Collections.

Objects and Abstractions

  • Abstraction in Java is achieved through Abstract Classes and Interfaces.
  • Abstraction hides implementation details from the user, who only gets the functionality.

Abstract Class

  • Definition: An abstract class is a class that is declared abstract and may or may not include abstract methods.
  • Characteristics:
    • Cannot be instantiated.
    • Can be subclassed.
    • If a class includes abstract methods, the class itself must be declared abstract.
  • Notes:
    • If a class is abstract, it cannot be instantiated.
    • When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class.
    • If a subclass does not provide implementations, it must also be declared abstract.

Interfaces

  • Definition: A contract in OO programming that bundles common functionality in classes that are not part of the inheritance hierarchy.
  • Characteristics:
    • Completely "abstract class" that groups related methods with empty bodies.
    • Used to provide a set of method signatures.
    • Provides return values of methods.
    • Tells us how to use an object that implements the interface.
  • Notes:
    • If an abstract class has nothing other than public static final properties and abstract methods, it could be made into an interface.
    • All methods in an interface are abstract, so there is no need to declare them as abstract.

Interface Example

  • A subclass implements an interface using the implements keyword.
  • Recall: Subclass extends an abstract class.

Collections

  • Creation:
    • Array: String studentName[] = new String[];
    • ArrayList: List studentName = new ArrayList&lt;&gt;();
  • Operations:
    • Array: studentName[i++] = “Peter”;
    • ArrayList: studentName.add(“Peter”);
  • Printing:
    • Array: `for(int i=0; i

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

Description

This quiz covers lecture notes on Object-Oriented Programming (OOP) for CST8132, a Computer Engineering Technology course at Algonquin College.

More Like This

Use Quizgecko on...
Browser
Browser