Software Engineering Lecture 2: Object-Oriented Programming Concepts in Python

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

Which OOP concept involves creating objects from classes?

  • Instantiation (correct)
  • Encapsulation
  • Abstraction
  • Polymorphism

What does encapsulation describe in object-oriented programming (OOP)?

  • Encapsulation is the process of creating objects from classes.
  • Encapsulation means object instantiation and accessing instance attributes.
  • Encapsulation is the idea of wrapping data and the methods that work on data within one unit. (correct)
  • Encapsulation refers to the inheritance principle and how to inherit a class.

What does inheritance principle refer to in OOP?

  • It refers to the process of object instantiation.
  • It refers to the idea of wrapping data and methods within one unit.
  • It refers to the process of creating classes.
  • It refers to the ability of objects to have a mix of inherited and unique methods. (correct)

What is the purpose of class abstraction in OOP?

<p>Class abstraction involves hiding the complex implementation details and showing only the necessary features of the object. (A)</p> Signup and view all the answers

What does polymorphism allow objects to have in OOP?

<p>A mix of some inherited methods and some unique to their own class. (C)</p> Signup and view all the answers

In OOP, what describes the idea of wrapping data and methods within one unit?

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

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

<p>To prevent accidental modification of data by restricting access to variables and methods (A)</p> Signup and view all the answers

In C#, which access specifier allows class members to be accessed from anywhere in the code?

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

What is the role of the underscore symbol in Python with regards to access control?

<p>Indicates a private data member or member function of a class (C)</p> Signup and view all the answers

Which type of variable in Python is easily accessible from any part of the program?

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

What does the 'protected' access specifier in C# allow?

<p>Access only within the class or in child/derived classes (B)</p> Signup and view all the answers

Which programming languages use access specifiers to define the scope and visibility of a class and its members?

<p>Both C# and Python (B)</p> Signup and view all the answers

What is the primary role of access specifiers in programming languages?

<p>To restrict access to class members and control visibility (B)</p> Signup and view all the answers

Which type of variable can only be accessed within the class in C#?

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

What is the fundamental building block for constructing software in functional programming?

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

In functional programming, what are functions treated as?

<p>First-class objects (D)</p> Signup and view all the answers

Which type of functions does functional programming emphasize?

<p>Pure functions without side effects (A)</p> Signup and view all the answers

What concept in functional programming involves functions that operate on other functions?

<p>Higher order functions (D)</p> Signup and view all the answers

According to the text, what is an important idea in functional programming related to the treatment of functions?

<p>First-class treatment of functions (C)</p> Signup and view all the answers

What is a key characteristic of functional programming in relation to the use of functions?

<p>Functions are only used for calculations (A)</p> Signup and view all the answers

Which of the following is NOT a characteristic of functional programming?

<p>Modifying the state of the system (A)</p> Signup and view all the answers

What is a pure function in functional programming?

<p>A function that calculates a result without any side effects (D)</p> Signup and view all the answers

What does a pure function in functional programming depend on?

<p>Input parameters (C)</p> Signup and view all the answers

What is the primary characteristic of first-class functions in functional programming?

<p>They can be stored in a variable, and passed as an argument to a function, or returned as the result of a function. (A)</p> Signup and view all the answers

What does immutability refer to in functional programming?

<p>Objects that cannot be modified after they have been created (D)</p> Signup and view all the answers

Which of the following is an example of a pure function?

<p>Finding the length of a string (A)</p> Signup and view all the answers

In functional programming, what does lazy evaluation emphasize?

<p><code>Evaluation</code> only when the result is required (B)</p> Signup and view all the answers

Which of the following is NOT allowed in pure functions in functional programming?

<p><code>Writing to a file or database</code> (C)</p> Signup and view all the answers

What does recursion over loops emphasize in functional programming?

<p><code>Recursion</code> as an alternative to traditional looping (A)</p> Signup and view all the answers

What is the purpose of higher-order functions in functional programming?

<p>To pass functions as arguments or return them (D)</p> Signup and view all the answers

Flashcards are hidden until you start studying

More Like This

Use Quizgecko on...
Browser
Browser