Free Bachelor of Computer Engineering Object Oriented Programming Questions and Answers β Questions and Answers
Question 1: Who invented the OOP?
- Adele Goldberg
- Dennis Ritchie
- Andrea Ferro
- Alan Kay (Correct answer)
Correct answer: Alan Kay
Alan Kay is widely credited with coining the term 'Object-Oriented Programming' and developing the Smalltalk language, which was a pioneering object-oriented language. His work at Xerox PARC in the 1970s laid much of the conceptual groundwork for OOP as we know it today. While Simula introduced many OOP concepts earlier, Kay's contributions were pivotal in popularizing and defining the paradigm.
Question 2: What does a general definition of OOP not include as an attribute?
- Code reusability
- Duplicate/Redundant data (Correct answer)
- Efficient Code
- Modularity
Correct answer: Duplicate/Redundant data
Object-Oriented Programming (OOP) aims to reduce data redundancy and improve data integrity through concepts like encapsulation and data hiding. Attributes like code reusability (via inheritance), efficient code, and modularity are core benefits and characteristics of OOP. Duplicate/redundant data is generally a problem that OOP seeks to mitigate, not an inherent attribute.
Question 3: Which programming language was the first to focus solely on objects?
- SmallTalk (Correct answer)
- C++
- Kotlin
- Java
Correct answer: SmallTalk
Smalltalk, developed by Alan Kay and his team in the 1970s, was the first programming language to fully embrace and implement the object-oriented paradigm, where everything is an object. While Simula introduced object-oriented concepts earlier, Smalltalk was designed from the ground up with a pure object model, making it a foundational language for OOP.
Question 4: When did the OOP concept initially come into existence?
- 1970βs (Correct answer)
- 1980βs
- 1993
- 1995
Correct answer: 1970βs
The core concepts of Object-Oriented Programming, including the term itself, were largely developed and popularized in the 1970s. Alan Kay's work on Smalltalk at Xerox PARC during this decade was instrumental in defining and demonstrating the paradigm. While Simula in the 1960s had some object-oriented features, the 1970s saw the formalization and significant advancement of OOP.
Question 5: What attribute of OOP denotes code reuse?
- Polymorphism
- Encapsulation
- Abstraction
- Inheritance (Correct answer)
Correct answer: Inheritance
Inheritance is the OOP principle that directly enables code reuse. It allows a new class (derived class) to inherit properties and methods from an existing class (base class). This means that common functionalities can be defined once in a base class and then reused by multiple derived classes, reducing redundancy and promoting modularity.
Question 6: Which header file does C++ need to use OOP?
- stdlib.h
- iostream.h
- OOP can be used without using any header file (Correct answer)
- stdio.h
Correct answer: OOP can be used without using any header file
Object-Oriented Programming (OOP) is a programming paradigm, not a specific library or set of functions requiring a particular header file. C++ inherently supports OOP features like classes, objects, inheritance, and polymorphism as part of its language syntax and semantics. Therefore, you can define and use classes and objects without including any specific header file dedicated to OOP itself.
Question 7: Why does Java include some OOP features?
- It supports usual declaration of primitive data types (Correct answer)
- It allows code to be written outside classes
- It doesnβt support all types of inheritance
- It does not support pointers
Correct answer: It supports usual declaration of primitive data types
While Java is fundamentally an object-oriented language, it includes primitive data types (like `int`, `char`, `boolean`) which are not objects, for performance and simplicity. This blend of primitive types with a strong OOP model makes Java a hybrid language in practice, even though it's predominantly object-oriented. The other options are incorrect as Java does not allow code outside classes, supports various inheritance types (except multiple class inheritance), and does not support explicit pointers.
Question 8: Which of the following is not a component of OOP?
- Data binding
- Platform independent (Correct answer)
- Data hiding
- Message passing
Correct answer: Platform independent
Platform independence is a characteristic of certain programming languages (like Java) or environments, meaning code can run on different operating systems without modification. While many OOP languages aim for platform independence, it is not an inherent component or principle of the OOP paradigm itself. Data binding, data hiding (encapsulation), and message passing are all core concepts within OOP.
Question 9: What is the proper inheritance syntax?
- class derived_classname : access base_classname{ /*define class body*/ }; (Correct answer)
- class base_classname :access derived_classname{ /*define class body*/ };
- class base_classname : derived_classname{ /*define class body*/ };
- class derived_classname : base_classname{ /*define class body*/ };
Correct answer: class derived_classname : access base_classname{ /*define class body*/ };
In C++, the correct syntax for inheritance involves specifying the derived class, followed by a colon, an access specifier (like `public`, `protected`, or `private`), and then the base class name. This structure clearly indicates that `derived_classname` inherits from `base_classname` with a specified level of access control, defining how members of the base class are accessed in the derived class.
Question 10: The characteristic that allows one object to interact with another object is .
- Message Passingc (Correct answer)
- Data Binding
- Message reading
- Data transfer
Correct answer: Message Passingc
In Object-Oriented Programming, 'message passing' is the mechanism by which objects communicate and interact with each other. When one object calls a method on another object, it is essentially sending a 'message' to that object, requesting it to perform a specific action or provide some data. This promotes modularity and loose coupling between objects.
Question 11: Which of the following statements is true for an OOP language?
- The language must follow only 3 features of OOP
- The language should follow at least 1 feature of OOP
- The language should follow 3 or more features of OOP
- The language must follow all the rules of OOP (Correct answer)
Correct answer: The language must follow all the rules of OOP
For a language to be considered truly object-oriented, it is generally expected to support the fundamental pillars of OOP: encapsulation, inheritance, and polymorphism. While some languages might incorporate a few OOP features, a language fully adhering to the paradigm will implement all these core concepts. This ensures a consistent and complete object-oriented approach.
Question 12: How many different kinds of access specifiers are there in OOP (C++)?
- 1
- 2
- 3 (Correct answer)
- 4
Correct answer: 3
In C++, there are three primary access specifiers: `public`, `protected`, and `private`. These specifiers control the visibility and accessibility of class members (data and functions) from outside the class or from derived classes. They are fundamental to encapsulation and information hiding in C++ OOP.
Question 13: Which OOP principle is most prominently applied in multilevel inheritance?
- Flexibility
- Code reusability (Correct answer)
- Code efficiency
- Code readability
Correct answer: Code reusability
Multilevel inheritance, where a class inherits from another class which itself inherits from a third class, primarily emphasizes code reusability. It allows for a hierarchical structure where common functionalities can be defined at higher levels and reused by subsequent derived classes, building upon existing code rather than rewriting it. This promotes efficient development and maintenance.
Question 14: What in OOP is encapsulation?
- It is a way of combining various data members and member functions into a single unit which can operate on any data
- It is a way of combining various data members and member functions that operate on those data members into a single unit (Correct answer)
- It is a way of combining various member functions into a single unit
- It is a way of combining various data members into a single unit
Correct answer: It is a way of combining various data members and member functions that operate on those data members into a single unit
Encapsulation is a core OOP principle that involves bundling data (data members) and the methods (member functions) that operate on that data into a single unit, typically a class. It also often includes data hiding, where the internal state of an object is protected from direct external access, and can only be modified through its public methods. This promotes data integrity and modularity.
Question 15: Regarding polymorphism, which of the following is false?
- Increases overhead of function definition always (Correct answer)
- Helps in redefining the same functionality
- Ease in readability of program
- It is feature of OOP
Correct answer: Increases overhead of function definition always
Polymorphism, meaning 'many forms,' allows objects of different classes to be treated as objects of a common type, enabling a single interface to represent different underlying forms. While dynamic polymorphism (runtime polymorphism) might introduce a slight overhead due to virtual function tables, it does not always increase the overhead of function definition. It primarily helps in redefining functionality, improving readability, and is a fundamental OOP feature.
Question 16: In object-oriented programming, what exactly is an abstraction?
- Hiding the important data
- Showing the important data
- Hiding the implementation and showing only the features (Correct answer)
- Hiding the implementation
Correct answer: Hiding the implementation and showing only the features
Abstraction in OOP focuses on showing only essential information to the user and hiding the complex implementation details. It allows you to define the 'what' an object does without revealing the 'how' it does it. This simplifies the system's view, making it easier to manage and understand, and allows for changes in implementation without affecting the external interface.
Who invented the OOP?