8 Lecture
CS304
Midterm & Final Term Short Notes
MEMBER FUNCTIONS
Member functions, also known as methods, are functions that are defined within a class and are used to perform operations on the objects of that class. They have access to the data members of the class and can manipulate them as necessary. Membe
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
- What is the primary purpose of member functions in object-oriented programming?
A. To declare variables
B. To initialize objects
C. To perform operations on objects
D. To create new objects
Answer: C
Which keyword is used to define a member function in C++?
A. class
B. function
C. method
D. this
Answer: C
Which type of member function can access private data members of a class?
A. Public
B. Private
C. Protected
D. Friend
Answer: B
Which type of member function does not have access to the this pointer?
A. Static
B. Virtual
C. Inline
D. Friend
Answer: A
Which keyword is used to call a member function on an object in C++?
A. new
B. delete
C. this
D. dot operator (.)
Answer: D
Which type of member function is used to initialize an object with a set of default values?
A. Constructor
B. Destructor
C. Virtual function
D. Operator function
Answer: A
Which type of member function is called automatically when an object is destroyed?
A. Constructor
B. Destructor
C. Virtual function
D. Operator function
Answer: B
Which type of member function can be called without creating an object of the class?
A. Constructor
B. Destructor
C. Static function
D. Friend function
Answer: C
Which keyword is used to access a data member of a class within a member function?
A. private
B. public
C. protected
D. this
Answer: D
Which type of member function is used to overload operators such as +, -, *, and /?
A. Constructor
B. Destructor
C. Virtual function
D. Operator function
Answer: D
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is the difference between a member function and a non-member function? Answer: A member function is defined within a class and has access to the data members of the class, whereas a non-member function is defined outside of the class and does not have access to the data members. What is the purpose of a constructor member function? Answer: A constructor member function is used to initialize an object of a class with a set of default values. What is the purpose of a destructor member function? Answer: A destructor member function is called automatically when an object is destroyed and is used to free up any resources allocated by the object. What is a static member function? Answer: A static member function is a function that can be called without creating an object of the class, and it has access only to static data members of the class. Can a member function be overloaded? Answer: Yes, a member function can be overloaded by defining two or more functions with the same name but different parameters or return types. What is the difference between a public and private member function? Answer: A public member function can be accessed by any code that has access to the object, whereas a private member function can only be accessed by other member functions of the class. Can a member function be declared as both virtual and static? Answer: No, a member function cannot be declared as both virtual and static because a virtual function requires a virtual table, whereas a static function does not. What is the purpose of the keyword 'this' in a member function? Answer: The keyword 'this' is a pointer to the current object, and it is used to access the data members and other member functions of the object. Can a constructor member function be overloaded? Answer: Yes, a constructor member function can be overloaded by defining two or more constructors with different parameters. What is the difference between a member function and a friend function? Answer: A member function is defined within a class and has access to the data members of the class, whereas a friend function is not a member of the class but has access to the private and protected members of the class.