Download Past Papers and Test Preparation Data for Computer Science Lecturer Exam - Prof. Raza and more Lecture notes C programming in PDF only on Docsity!
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
Object Oriented Programming
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-
computer-science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
1. Questions and Answers – OOPs Basic Concepts
This set of Object Oriented Programming online test focuses on “OOP Basic Concepts”.
- Which was the first purely object oriented programming language developed? a) Java b) C++ c) SmallTalk d) Kotlin View Answer Answer: c Explanation: SmallTalk was the first programming language developed which was purely object oriented. It was developed by Alan Kay. OOP concept came into picture in 1970’s.
- Which of the following best defines a class? a) Parent of an object b) Instance of an object c) Blueprint of an object d) Scope of an object View Answer Answer: b Explanation: A class is Blueprint of an object which describes/ shows all the functions and data that are provided by an object of a specific class. It can’t be called as parent or instance of an object. Class in general describes all the properties of an object.
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
- Who invented OOP? a) Alan Kay b) Andrea Ferro c) Dennis Ritchie d) Adele Goldberg View Answer
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-
computer-science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Answer: a Explanation: Alan Kay invented OOP, Andrea Ferro was a part of SmallTalk Development. Dennis invented C++ and Adele Goldberg was in team to develop SmallTalk but Alan actually had got rewarded for OOP.
- What is the additional feature in classes that was not in structures? a) Data members b) Member functions c) Static data allowed d) Public access specifier View Answer Answer: b Explanation: Member functions are allowed inside a class but were not present in structure concept. Data members, static data and public access specifiers were present in structures too.
- Which is not feature of OOP in general definitions? a) Code reusability b) Modularity c) Duplicate/Redundant data d) Efficient Code
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer- b) Java c) Kotlin d) Small Talk View Answer Answer: b Explanation: Java doesn’t support all 4 types of inheritance. It doesn’t support multiple inheritance. But the multiple inheritance can be implemented using interfaces in Java.
- How many classes can be defined in a single program? a) Only 1 b) Only 100 c) Only 999 d) As many as you want View Answer Answer: d Explanation: Any number of classes can be defined inside a program, provided that their names are different. In java, if public class is present then it must have the same name as that of file.
- When OOP concept did first came into picture? a) 1970’s b) 1980’s c) 1993 d) 1995 View Answer Answer: a
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer- Explanation: OOP first came into picture in 1970’s by Alan and his team. Later it was used by some programming languages and got implemented successfully, SmallTalk was first language to use pure OOP and followed all rules strictly.
- Why Java is Partially OOP language? a) It supports usual declaration of primitive data types b) It doesn’t support all types of inheritance c) It allows code to be written outside classes d) It does not support pointers View Answer Answer: a Explanation: As Java supports usual declaration of data variables, it is partial implementation of OOP. Because according to rules of OOP, object constructors must be used, even for declaration of variables.
- Which concept of OOP is false for C++? a) Code can be written without using classes b) Code must contain at least one class c) A class must have member functions d) At least one object should be declared in code View Answer
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-
computer-science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Answer: b Explanation: In C++, it’s not necessary to use classes, and hence codes can be written without using OOP concept. Classes may or may not contain member functions, so it’s not a necessary condition in C++. And, an object can only be declared in a code if its class is defined/included via header file. advertisement
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer- Answer: a Explanation: Use of this pointer allows an object to call data and methods of itself whenever needed. This helps us call the members of an object recursively, and differentiate the variables of different scopes.
2. Questions and Answers – Classes This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) focuses on “Classes”.
- Which of the following is not type of class? a) Abstract Class b) Final Class c) Start Class d) String Class View Answer Answer: c Explanation: Only 9 types of classes are provided in general, namely, abstract, final, mutable, wrapper, anonymous, input-output, string, system, network. We may further divide the classes into parent class and subclass if inheritance is used.
- Class is pass by _______ a) Value b) Reference c) Value or Reference, depending on program d) Copy View Answer Answer: b
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer- Explanation: Classes are pass by reference, and the structures are pass by copy. It doesn’t depend on program.
- What is default access specifier for data members or member functions declared within a class without any specifier, in C++? a) Private b) Protected c) Public d) Depends on compiler View Answer Answer: a Explanation: The data members and member functions are Private by default in C++ classes, if none of the access specifier is used. It is actually made to increase the privacy of data.
- Which is most appropriate comment on following class definition : class Student { int a; public : float a; }; a) Error : same variable name can’t be used twice b) Error : Public must come first c) Error : data types are different for same variable d) It is correct View Answer Answer: a
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer- View Answer
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-
computer-science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Answer: d Explanation: Abstract classes can have member functions with no implementation, where the inheriting subclasses must implement those functions.
- Which of the following describes a friend class? a) Friend class can access all the private members of the class, of which it is a friend b) Friend class can only access protected members of the class, of which it is a friend c) Friend class don’t have any implementation d) Friend class can’t access any data member of another class but can use it’s methods View Answer Answer: a Explanation: A friend class can access all the private members of another class, of which it is friend. It is a special class provided to use when you need to reuse the data of a class but don’t want that class to have those special functions.
- What is scope of a class nested inside another class? a) Protected scope b) Private scope c) Global scope d) Depends on access specifier and inheritance used View Answer Answer: d Explanation: It depends on the access specifier and the type of inheritance used with the class, because if the class is inherited then the nested class can be used by subclass too, provided it’s not of private type.
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
- Class with main() function can be inherited (True/False) a) True b) False View Answer Answer: a Explanation: The class containing main function can be inherited and hence the program can be executed using the derived class names also in java. advertisement
- Which among the following is false, for member function of a class? a) All member functions must be defined b) Member functions can be defined inside or outside the class body c) Member functions need not be declared inside the class definition d) Member functions can be made friend to another class using friend keyword View Answer Answer: c Explanation: Member functions must be declared inside class body, thought the definition can be given outside the class body. There is no way to declare the member functions inside the class.
- Which syntax for class definition is wrong? a) class student{ }; b) student class{ }; c) class student{ public: student(int a){ } }; d) class student{ student(int a){} }; View Answer
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer- d) Abstract class View Answer Answer: d Explanation: Instance of abstract class can’t be created as it will not have any constructor of its own, hence while creating an instance of class, it can’t initialize the object members. Actually the class inheriting the abstract class can have its instance, because it will have implementation of all members.
3. Questions and Answers – Objects This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) focuses on “Objects”.
- Which definition best describes an object? a) Instance of a class b) Instance of itself c) Child of a class d) Overview of a class View Answer Answer: a Explanation: An object is instance of its class. It can be declared in the same way that a variable is declared, only thing is you have to use class name as the data type.
- How many objects can be declared of a specific class in a single program? a) 32768 b) 127 c) 1 d) As many as you want View Answer
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer- Answer: d Explanation: You can create as many objects of a specific class as you want, provided enough memory is available.
- Which among the following is false? a) Object must be created before using members of a class b) Memory for an object is allocated only after its constructor is called c) Objects can’t be passed by reference d) Objects size depends on its class data members View Answer Answer: c Explanation: Objects can be passed by reference. Objects can be passed by value also. If object of a class is not created, we can’t use members of that class.
- Which of the following is incorrect? a) class student{ }s; b) class student{ }; student s; c) class student{ }s[]; d) class student{ }; student s[5]; View Answer Answer: c Explanation: The array must be specified with a size. You can’t declare object array, or any other linear array without specifying its size. It’s a mandatory field.
- The object can’t be: a) Passed by reference b) Passed by value
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer- a) Using dot operator/period symbol b) Using scope resolution operator c) Using member names directly d) Using pointer only View Answer Answer: a Explanation: Using dot operator after the name of object we can access its members. It is not necessary to use the pointers. We can’t use the names directly because it may be used outside the class.
- If a local class is defined in a function, which of the following is true for an object of that class? a) Object is accessible outside the function b) Object can be declared inside any other function c) Object can be used to call other class members d) Object can be used/accessed/declared locally in that function. View Answer Answer: d Explanation: For an object which belongs to a local class, it is mandatory to declare and use the object within the function because the class is accessible locally within the class only.
- Which among the following is wrong? a) class student{ }; student s; b) abstract class student{ }; student s; c) abstract class student{ }s[50000000]; d) abstract class student{ }; class toppers: public student{ }; topper t; View Answer Answer: b
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer- Explanation: We can never create instance of an abstract class. Abstract classes doesn’t have constructors and hence when an instance is created there is no facility to initialize its members. Option d is correct because topper class is inheriting the base abstract class student, and hence topper class object can be created easily.
- Object declared in main() function: a) Can be used by any other function b) Can be used by main() function of any other program c) Can’t be used by any other function d) Can be accessed using scope resolution operator View Answer Answer: c Explanation: The object declared in main() have local scope inside main() function only. It can’t be used outside main() function. Scope resolution operator is used to access globally declared variables/objects.
- When an object is returned___________ a) A temporary object is created to return the value b) The same object used in function is used to return the value c) The Object can be returned without creation of temporary object d) Object are returned implicitly, we can’t say how it happens inside program View Answer Answer: a Explanation: A temporary object is created to return the value. It is created because object used in function is destroyed as soon as the function is returned. The temporary variable returns the value and then gets destroyed. advertisement
- Which among the following is correct? a) class student{ }s1,s2; s1.student()=s2.student();
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer- Explanation: It is the way we can initialize the data members for an object array using parameterized constructor. We can do this to pass our own intended values to initialize the object array data.
- Object can’t be used with pointers because they belong to user defined class, and compiler can’t decide the type of data may be used inside the class. (True/False) a) True b) False View Answer Answer: b Explanation: The explanation given is wrong because object can always be used with pointers like with any other variables. Compiler doesn’t have to know the structure of the class to use a pointer because the pointers only points to a memory address/stores that address. 4. Questions and Answers – OOPs Features This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) focuses on “OOP Features”.
- Which feature of OOP indicates code reusability? a) Encapsulation b) Inheritance c) Abstraction d) Polymorphism View Answer Answer: b Explanation: Inheritance indicates the code reusability. Encapsulation and abstraction are meant to hide/group data into one element. Polymorphism is to indicate different tasks performed by a single entity.
- If a function can perform more than 1 type of tasks, where the function name remains same, which feature of OOP is used here?
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer- a) Encapsulation b) Inheritance c) Polymorphism d) Abstraction View Answer Answer: c Explanation: For the feature given above, the OOP feature used is Polymorphism. Example of polymorphism in real life is a kid, who can be a student, a son, a brother depending on where he is.
- If different properties and functions of a real world entity is grouped or embedded into a single element, what is it called in OOP language? a) Inheritance b) Polymorphism c) Abstraction d) Encapsulation View Answer Answer: d Explanation: It is Encapsulation, which groups different properties and functions of a real world entity into single element. Abstraction, on other hand, is hiding of functional or exact working of codes and showing only the things which are required by the user.
- Which of the following is not feature of pure OOP? a) Classes must be used b) Inheritance c) Data may/may not be declared using object d) Functions Overloading View Answer