CUET CS Chapter-Classes and Objects

  • Board
    CBSE
  • Textbook
    NCERT
  • Class
    Class 12
  • Subject
    Computer Science
  • Chapter
    CUET CS Chapter-Classes and Objects
  • Chapter Name
    Classes and Objects
  • Category
    CUET (Common University Entrance Test) UG

MCQ-Based Questions for CUET Computer Science Chapter-Classes and Objects 

This page is prepared by HT experts and consists of MCQ-Based Questions for the CUET Computer Science chapter-Classes and Objects with a detailed explanation of all the questions asked from Classes and Objects. To find the solution to the MCQ questions click on the answer tab. Check out chapter-wise CUET computer science Practice MCQ Based Questions. 

Practice Questions for CUET Computer Science chapter-Classes and Objects SET-1

Computer Science - MCQ on Classes and Objects

Class XII

Q.1 The data members that are usually maintained to store values common to the entire class are

a) non-static members.

b) static data members.

c) initialized members.

d) abstract members.

Answer:

(b)

Explanation: A static data member is globally available for all the objects of that class type.

Q.2 The number of copies of static data member maintained for the entire class

a) is only one.

b) are two copies.

c) can be many.

d) are only 3 copies.

Answer:

a)

Explanation: There is only one copy maintained for the entire class, which is shared by all the objects of that class.

Q.3 Static data members are declared

a) within the class definition.

b) outside the class definition.

c) outside the main ().

d) with virtual keyword always.

Answer:

a)

Explanation: For making a data member static, the declaration is done within the class definition always.

Q.4 Static data members are defined

a) within the class definition.

b) outside the class definition.

c) outside the main ().

d) with static keyword always.

Answer:

(b)

Explanation: A static data member must be defined outside the class definition, as these are stored separately rather than as a part of the object.

Q.5 Static data members are also called as

a) variables.

b) fundamental data types.

c) class variables.

d) abstract data members.

Answer:

c)

Explanation: Since, they are associated with class itself rather than with any class object, they are also known as class variables.

Q.6 The statement int s:: count =10; is

a) the declaration of static data member count of class s.

b) the definition of static data member count of class s, that initializes count with value 10.

c) both declaration and definition of static data member count of class s, assigning value 10 to count.

d) declaration of static data member count of class s, and giving default value 10 to count.

Answer:

b) Explanation: It is definition of a static data member count of class s, and data member count is given initial value 10 at the time of definition.

Q.7 We cannot have a static data member

a) inside a global class.

b) inside a local class.

c) inside a class.

d) inside a derived class.

Answer:

(b)

Example: A local class is a class that has been defined inside a function.

Q.8 A static member function can access

a) static members of the same class only.

b) static members of any class.

c) static and non-static members of the same class.

d) static and non-static members of any class.

Answer:

a)

Explanation: A member function that accesses only the static members of a class may be declared as static.

Q.9 A static member function is invoked by using the

a) objects of the class.

b) class name instead of objects.

c) class variables.

d) dot operator.

Answer:

b) Explanation: Example: to call the static function abs() of class Z, we can invoke the function using Z:: abs(); statement.

Q.10 A member function can access

a) only ordinary members.

b) only static members.

c) both ordinary as well as static members.

d) Only global data members.

Answer:

c)

Explanation: A static member function can access only static members, whereas member functions can access both static and ordinary data members.

Computer Science - MCQ on Classes and Objects

Class XII

Q.1 In C++ programs, when an object is first created the special member function, which is automatically called is

a) destructor.

b) constructor.

c) malloc.

d) calloc.

Answer:

(b)

Explanation: The constructor is a special member function that allows us to set up values while defining the object, without the need to make a separate call to a member function.

Q.2 When an object is destroyed the function, which automatically gets

Called, is

a) destructor.

b) constructor.

c) malloc.

d) calloc.

Answer:

(a)

Explanation: The destructors are used to deallocate memory that was allocated for the object by the constructor.

Q.3 If, we are using two or more than two constructors in a class having different number of arguments, then the number of destructors used for that class, is

a) two.

b) same number of destructors as constructors.

c) only one.

d) one or more.

Answer:

(c)

Explanation: When an object gets created, constructor is called. When control goes outside main(), destructor function is invoked and object gets destroyed. For a class only one destructor is invoked for all the objects.

Q.4 If, we are using two or more than two constructors in a class having different number of arguments two and three respectively, then destructor used for that class, will have

a) zero argument .

b) two destructors one having two arguments and other three arguments.

c) two arguments.

d) three arguments.

Answer:

(a)

Explanation: Destructors take no arguments (the assumption being that there is only one way to destroy an object).

Q.5 If, I want to create a destructor having class name “example”, then the syntax, is

a) xample()

b) ~example()

c) ~example();

d) ~xample()

Answer:

(b)

Explanation: A destructor has the same name as the constructor (which is same as the class name) but is preceded by a tilde.

Q.6 The destructors used in c++ program do

a) not have a return value.

b) have a return value .

c) takes no arguments.

d) not gets automatically called.

Answer:

(a)

Explanation: The constructors can take any one or more arguments, whereas the destructors take no arguments. Both the constructors and destructors gets automatically called.

Q.7 If, we declare the object of a particular class type and the class does not have a constructor, then

a) it would be compiler error.

b) default constructor gets called automatically.

c) default constructor has to be called explicitly.

d) it would give run time error.

Answer:

(b)

Explanation: When no constructor is present in the class the compiler builds an implicit constructor.

Q.8 Usually the data and member functions in a class are

a) public and private.

b) public.

c) private.

d) private and public.

Answer:

(d)

Explanation: The data within a class is private i.e. the data is hidden so that it will be safe from accidental manipulation. The functions are public so that they can be accessed from outside the class.

Q.9 A class is a collection of data and functions that operate upon this data. Both data and functions can be

a) only private.

b) only public.

c) private and public.

d) private or public.

Answer:

(d)

Explanation: This essentially decides the access to the data and functions within the class.

Q.10 The class and the constructor function within it

a) can have different names

b) must have same names.

c) may or may not have same names.

d) can never have same names.

Answer:

(b)

Explanation: The constructor is a special member function that is automatically called when an object is created. It has same name as that of class.

Q.11 The function setdata()

a) sets the data items to given values.

b) displays the data items.

c) receives the values of data items.

d) prints the data items.

Answer:

(a)

Explanation: It assigns data in a specified format to the data transfer object or the clipboard data object.

Q.12 The process of creating an object is called

a) object creation.

b) object formation.

c) instantiation.

d) instant object.

Answer:

(c)

Explanation: An object is an instance of a class. It is the root of class hierarchy and the process of creating it is called instantiation.

Q.13 Like a structure, the body of the class is terminated by

a) colon.

b) comma.

c) semicolon.

d) colon.

Answer:

(c)

Explanation: The body of a class is delimited by braces and terminated by semicolon.

Q.14 Private keyword is used in c++ to implement a concept called

a) data binding.

b) data hiding

c) security.

d) polymorphism.

Answer:

(b)

Explanation: when we use private keyword it means that data is accessible within a class and it cannot be accessed outside the class.

Q.15 The techniques, which are used to prevent illegal users from accessing data are

a) security techniques.

b) data hiding techniques.

c) data implementation techniques.

d) data binding techniques.

Answer:

(a)

Explanation: Data hiding should not be confused with security techniques used to protect computer data. Security techniques prevent illegal user from accessing data. Data hiding, on the other hand, is used to protect well-intentioned users from honest mistakes.

Q.16 A function declared within the definition of a class is called

a) data.

b) method.

c) variable.

d) scope resolution operator.

Answer:

(b)

Explanation: A class is a collection of data types and functions, which operate on them. The functions defined within a class, is called as member functions or methods.

Q.17 Member functions is function defined within a class that acts on

a) the data members in the class.

b) the data members outside the class.

c) the methods within the class.

d) the objects.

Answer:

(a)

Explanation: There are two kinds of members in a class: data members and member functions. Data members are exactly like the variables in a structure and member functions act on data members in the class.

Q.18 Member functions of a class can be accessed

a) by a object of another class.

b) using scope resolution operator by an object of different class.

c) using dot operator by an object of that class.

d) by constructor of that class.

Answer:

(c)

Explanation: Member function is always called to operate on the specific object, not on the class in general. It is accessed using dot operator, which is also called as “class member access operator”.

Q.19 The constructors used in c++ programs do

a) not have a return type.

b) have a return value .

c) takes no arguments.

d) not gets automatically called.

Answer:

(a)

Explanation: The constructor is called automatically when an object is created, returning a value would not make any sense.

Q.20 The operator, which allocates memory from free store, is

a) delete

b) new

c) malloc()

d) free()

Answer:

(b)

Explanation: The new operator, when used with the pointer to a data type, a structure, or an array, allocates memory for the item and assigns the address of that memory to the pointer.

Q.21 In c++, the operator which returns to the free store the memory owned by the object is

a) malloc()

b) calloc()

c) free()

d) delete

Answer:

(d)

Explanation: The memory allocated from system heap using malloc(), calloc() and realloc() is deallocated using the function free() in C, whereas in C++ this work is done by delete operator.

Q.22 The default arguments are given in the

a) function prototype only.

b) function definition.

c) either function prototype or definition.

d) function calling.

Answer:

(a)

Explanation: In C++, we have an option for defining default values for arguments that are not passed when the function call is made. The compiler uses the prototype information to build a call, not the function definition.

Q.23 We can give additional meaning to operators in c++ using

a) function overloading.

b) operator overloading.

c) virtual pointers.

d) polymorphism.

Answer:

(b)

Explanation: By overloading operators like +,*,-which are supposed to work on standard data types like ints, floats etc they can work differently. Example, by overloading + operator it can be used to add two strings which is not possible in c.

Q.24 The code statement c3.add_complex(c1,c2; adds two complex numbers c1 and c2 and the result

a) will give an error inn this case.

b) need to be stored in another variable c4.

c) will return a value in another variable.

d) gets stored in c3 automatically.

Answer:

(d)

Explanation: There is no need to return a value, as the result gets stored in c3 when the function is called.

Q.25 The class is declared with the keyword

a) member.

b) classname.

c) class.

d) public.

Answer:

(c)

Explanation: The syntax of class declaration is:

class <classname>

{

private:

data members; member functions;

public:

data members ; member functions;

};

Q.26 Member access specifiers always end with

a) colon.

b) semicolon.

c) comma

d) dot.

Answer:

(b)

Explanation: Member access specifiers like private, protected and public can appear any number of times in a class and they always terminate with a colon (:)

Q.27 void display (void);

This code in C++ program signifies

a) member function.

b) data member.

c) object.

d) class.

Answer:

(a)

Explanation: There are two kinds of members in a class: data members and member functions. Data members are exactly like the variables in a structure and member functions act on data members in the class.

Q.28 Private members of a class are available to

a) only members outside the class.

b) only members of the class.

c) members of a program.

d) members of a package.

Answer:

(b)

Explanation: Any member having private keyword is accessible to members within the class.

Q.29 The operator which is used in situations, where a global variable exists within the same name as the local variable is called

a) arithmetic operator.

b) increment operator.

c) scope resolution operator.

d) dot operator.

Answer:

(c)

Explanation: Scope resolution operator is used in c++ class, when the member functions are declared outside the class definition.

Q.30 When the implementation is substituted into the code where the function call is made, that function is defined as

a) friend.

b) inline.

c) virtual.

d) member function.

Answer:

(b)

Explanation: At each place where there is a function call in the source file, the actual code from the function would be inserted, instead of a jump to the function.

Q.31 While manipulating objects for user programs, C++ maintains an internal pointer to point to the current object being operated upon. It is called as

a) this pointer.

b) pointer.

c) friend function.

d) abstraction.

Answer:

(a)

Explanation: Whenever a member function of an object is called, the compiler places the address of the object in pointer “this” before invoking the function.

Q.32 A function is made inline function, when

a) it is very big just like macros.

b) it is very small and does not return any value or contain any static variables.

c) it contains static variables and return a value.

d) it is a very big function and does not contain any static variables.

Answer:

(b)

Explanation: An inline function is a function whose code gets inserted into the

Caller’s stream code.

Q.33 Overuse of inline function can cause

a) code fragmentation.

b) code union.

c) insecurity of data.

d) encapsulation of data.

Answer:

(a)

Explanation: Inline functions improve performance by avoiding the overhead of the call itself but their overuse can lead to negative performance impact in paging environment.

Q.34 The number of access labels provided by class are

a) one.

b) two.

c) three.

d) four.

Answer:

(c)

Explanation: There are 3 access labels provided by the class: private, protected and public.

Q.35 The disadvantage of inline function call is

a) increases time as function is invoked again and again.

b) fragmentation of code.

c) memory is wasted.

d) it does not return any value.

Answer:

(c)

Explanation: Whenever the function is invoked the same function code is inserted in the program for every function call, so memory is wasted.

Q.36 The error in the below code is

{

int a,b;

public

void read();

}

a) no class declaration only.

b) no class declaration and no colon after public.

c) no class declaration and no semicolon after public.

d) no colon after public keyword only.

Answer:

(b)

Explanation: After all the access specifiers, public, private and protected colon comes and a class declaration having class keyword and class name is must for every class.

Q.37 Abstract class cannot have

a) zero instance.

b) any instance.

c) multiple instance.

d) zero and multiple instance.

Answer:

(b)

Explanation: An abstract class is a class, which cannot be instantiated. It has no instances.Abstract classesare classes that contain one or more abstract methods. An abstractmethod is a method that is declared, but contains no implementation.

Q.38 A structure containing a member that is a pointer to the same structure type is referred as

a) self–referential structure.

b) structure.

c) base structure.

d) derived structure.

Answer:

(a)

Explanation: Self–referential structures are useful for forming lined data structures such as linked lists, stacks and trees.

Q.39Reusability of classes is one of the major characteristics of OOPS. It is implemented in c++ through

a) polymorphism.

b) inheritance.

c) data abstraction.

d) encapsulation.

Answer:

(b)

Explanation: Inheritance is the property by which derived class inherits the characteristics and properties of base class.

Q.40 The access specifier, which is particularly used so that members can be accessed only by the base class and derived class, is

a) private

b) public

c) protect.

d) protected.

Answer:

(d)

Explanation: A protected keyword is a member access modifier. A protected member is accessible within a class in which it is declared and from within any class derived from that class declared by the member.

Q.41 The logical abstract base class for a class called “footballPlayer” is

a) salary.

b) sport.

c) athlete.

d) team.

Answer:

(c)

Explanation: An abstract class is a class, which cannot be instantiated. It has no instances.

Q.42 The essential characteristics of an object, which distinguish it from all other kinds of objects, is

a) aggregation.

b) abstraction.

c) modularity.

d) encapsulation.

Answer:

(b)

Explanation: Abstraction is focusing on the details of an object leaving behind the implementation details, which are not essential.

Practice Questions for CUET Computer Science chapter-Classes and Objects SET-2

Q.43 The good example of a method that is shared by all instance of a class is

a) constructor.

b) attribute.

c) constructor and attribute.

d) overloading.

Answer:

a)

Explanation: A constructor is a special member function, which will construct an object with user-defined values whenever object is created. It is a special method used in oops, which puts the object member into a valid state.

Q.44 An abstract class is the class that

a) does not have method definitions.

b) has a constructor which takes no arguments.

c) must have a function definition equal to zero.

d) can only exist during the planning phase.

Answer:

(a)

Explanation: Abstract classes are classes, which cannot be instantiated but they can have sub classes. They do not have method definitions but the prototypes and declarations can be done.

Q.44 Interface is also known as

a) virtual class.

b) dependent class.

c) pure abstract class.

d) class.

Answer:

(c)

Explanation: Interface generally refers to an abstraction that an entity provides of itself to the outside. This separates the methods of external communication from internal operation and allows it to be internally modified without affecting the way outside entities interact with it, as well as provide multiple abstractions of itself.

Q.45 A static data member must be defined

a) inside the class definition.

b) outside the class definition.

c) with the class definition.

d) outside main().

Answer:

(b)

Explanation: A static data member is visible only within the class, however its lifetime is the entire program.

Q.46 A static data member must be declared

a) with the class definition.

b) outside the class definition.

c) within the class definition.

d) outside main().

Answer:

(c)

Explanation: The declaration of a static data member within the class definition is similar to any other variable declaration except that it starts with the keyword static.

Q.47 If, the object is declared outside all the function bodies, then it is called a

a) local object.

b) global object

c) either local or global object.

d) outer object.

Answer:

(b)

Explanation: The global object is available to all the functions in the program i.e. this object can be used anywhere in the program. A global object only is declared using a global class type.

Q.48 If, the object is declared within the function body, then it is called a

a) local object.

b) global object

c) either local or global object.

d) inner object.

Answer:

(a)

Explanation: A local object can be accessed only within the function body and it cannot be used outside the function. A local object can be created from both types: local and global.

Q.49 If, a class object can be declared anywhere within the program, then it is called a

a) outer class.

b) local class.

c) global class.

d) super class.

Answer:

(c)

Explanation: A class is said to be a global class, if its definition occurs outside the bodies of all functions in a program.

Q.50 If, a class object is declared within the function that defines this class type, then it is called a

a) inner class.

b) local class.

c) global class.

d) sub class.

Answer: