Object Oriented Programming

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

How is data abstraction accomplished?

Data abstraction is accomplished with the help of abstract methods or abstract classes.

What are some other programming paradigms

Imperative, Declarative

What is the difference between overloading and overriding?

Over loading is a compile polymorphism feature in which an entity has multiple implementations with the same name. For example, Method overloading and Operator overloading. Overriding is a runtime polymorphism feature in which an entity has the same name, but its implementation changes during execution. For example - "Method Overriding"

What are some major Object Oriented Programming Languages?

Java, C++, Javascript, Python, PHP, Perl

What is a subclass?

The subclass is a part of Inheritance. The subclass is an entity, which inherits from another class. It is also known as the child class.

Explain inheritance with an example

car, truck, bus. different behaviors and characteristics but common elements among them.

What are the main features of OOP?

- Inheritance - Encapsulation - Polymorphism - Data Abstraction

What are the various types of inheritance?

- Single inheritance A->B - Multiple inheritances A -> C <- B - Multi-level inheritance A-> B -> C - Hierarchical inheritance B <- A -> D - Hybrid inheritance A-> B -> D <- C <- A

What is a class?

A class can be understood as a template or blueprint, which contains some values, known as member data or members, and some set of rules, known as behaviors or functions. So when an object is created, it automatically takes the data and functions that are defined in the class. Therefore, the class is basically a template or blueprint for objects. Also, one can create as many objects as they want based on a class. E.g. a template for cars

What are access specifiers and what is their significance?

Access specifiers, as the name suggests, are a special type of keywords, which are used to control or specify the accessibility of entities like classes, methods, etc. Some of the access specifiers or access modifiers include "private", "public", etc. These access specifiers also play a very vital role in achieving Encapsulation - one of the major features of OOPs.

What is an abstract class?

An abstract class is a special class containing abstract methods. The significance of abstract class is that the

What is an exception?

An exception can be considered as a special event, which is raised during the execution of a program at runtime, that brings the execution to a halt. The reason for the exception is mainly due to a position in the program, where the user wants to do something for which the program is not specified, like undesirable input.

What is an object?

An object refers to an instance of the class, which contains the instance of the members and behaviors defined in the class template. In the real world, an object is an actual entity to which a user interacts, whereas class is just the template for that object. So the objects consume space and have some characteristic behavior. E.g. A ford fusion

How much memory does a class occupy?

Classes do not consume memory. They are just a blueprint based on which objects are created. Now when objects are created, they actually initialize the class members and methods and therefore consume memory.

What is compile time polymorphism and how is it different from runtime polymorphism?

Compile time polymorphism, also known as static polymorphism, refers to the type of polymorphism that happens at compile time. What it means is that the compiler decides what shape or value has to be taken by the entity. Runtime polymorphism, also known as dynamic polymorphism, refers to the type of polymorphism that happens at the run time. What it means is that it can't be decided by the compiler. Therefore what shape or value has to be taken depends upon the execution.

Static polymorphism is also known as:

Compile-time polymorphism

What is a constructor? Copy-constructor? Destructor?

Constructors are special methods whose name is the same as the class name. The constructors serve the special purpose of initializing the objects. Copy-constructors is a type of constructor, whose purpose is to copy an object to another. What it means is that a copy constructor will clone an object and its values, into another object, provided that both objects are of the same class. Destructor - Contrary to constructors, which initialize objects and specify space for them, Destructors are also special methods. But they free up the resources and memory occupied by an object. Destructors are automatically called when an object is being destroyed.

What is abstraction?

If you are a user, and you have a problem statement, you don't want to know the components of the software, how it works, or how it's made. You only want to know how the software solves your problem. Abstraction is the method of hiding unnecessary details from the necessary ones. It is one of the main features of OOPs. For example, consider a car. You only need to know how to run a car, and not how the wires are connected inside of it.

How is an abstract class different from an interface?

Interface and abstract class both are special types of classes that contain only the methods declaration and not their implementation. But the interface is entirely different from an abstract class. The main difference between the two is that, when an interface is implemented, the subclass must define all its methods and provide its implementation. Whereas when an abstract class is inherited, the subclass does not need to provide the definition of its abstract method, until and unless the subclass is using it. Also, an abstract class can contain abstract methods as well as non-abstract methods.

What is an interface?

It is a special type of class, which contains methods, but not their definition. Only the declaration of methods is allowed inside an interface. To use an interface, you cannot create objects. Instead, you need to implement that interface and define the methods for their implementation.

What are the limitations of inheritance?

Needs more time to process, as it needs to navigate through multiple classes for its implementation. Also, the classes involved in inheritance - the base class and the child class are very tightly coupled together. So if one needs to make some changes, they might need to do nested changes in both classes. Inheritance might have complex implementation - so if not correctly implemented it can lead to errors or incorrect outputs.

Is it always necessary to create objects from classes?

No. An object is necessary to be created if the base class has non-static methods. But if the class has static methods, then objects don't need to be created. You can call the class method directly in this case, using the class name.

What is meant by the term Object-Oriented Programming (OOP)

OOPs refers to Object-Oriented Programming. It is the programming paradigm that is defined using objects. Objects can be considered as real-world instances of entities like class, that have some characteristics and behaviors.

What is meant by Garbage Collection in OOPs world?

Object-oriented programming revolves around entities like objects. Each object consumes memory and there can be multiple objects of a class. So if these objects and their memories are not handled properly, then it might lead to certain memory-related errors and the system might fail. Garbage collection refers to this mechanism of handling the memory in the program. Through garbage collection, the unwanted memory is freed up by removing the objects that are no longer needed.

What is Polymorphism?

Polymorphism refers to the process by which some code, data, method, or object behaves differently under different circumstances or contexts. Compile-time polymorphism and Run-time polymorphism are the two types of polymorphisms in OOP languages.

In encapsulation, what is "private", "protected", and "public"

Private - Only the current class will have access to the field or method. Protected - Only the current class and subclasses of this class will have access to the field or method. Public - Any class can refer to the field or call the method.

Dynamic polymorphism is also known as:

Runtime polymorphism

Define a superclass?

Superclass is also a part of Inheritance. The superclass is an entity, which allows subclasses or child classes to inherit from itself.

What is encapsulation?

The method of putting everything that is required to do the job, inside a capsule and presenting that capsule to the user. What it means is that by Encapsulation, all the necessary data and methods are bound together and all the unnecessary details are hidden to the normal user. So Encapsulation is the process of binding data members and methods of a program together to do a specific job, without revealing unnecessary details. Encapsulation can also be defined in two different ways: 1. Data hiding: Encapsulation is the process of hiding unwanted information, such as restricting access to any member of an object. 2. Data Binding: Encapsulation is the process of binding the data members and the methods together as a whole, as a class.

What is inheritance?

The term inheritance means receiving some quality or behavior from a parent to an offspring. In object-oriented programming, inheritance is the mechanism by which an object or class (referred to as a child) is created using the definition of another object or class (referred to as a parent). Inheritance not only helps to keep the implementation simpler, but also helps to facilitate code reuse.

What is the need for OOPs?

There are many reasons why OOPs is mostly preferred, but the most important among them are: - OOPs helps users to understand the software easily, although they don't know the actual implementation. - With OOPs, the readability, understandability, and maintainability of the code increases multifold. - Even very big software can be easily written and managed easily using OOPs.


Kaugnay na mga set ng pag-aaral

Chapter 4.1 Energy, Producers, and Consumers

View Set

Personal & Family Finance Exam 3

View Set

Illinois Life Producer State - Designated Exam SIMULATOR (75 questions)

View Set

NU 302 Module 3 Exam: Chapter 4 Evidence Based Practice

View Set

New Hampshire Hunters Education Study Guide - Fall 2020

View Set

Psychology Chapter 6, Psychology Chapter 7, Psychology Chapter 8

View Set

Advantages and disadvantages of communication methods

View Set

NCLEX Thermoregulation Questions

View Set