Software Development Exam  >  Software Development Tests  >  Test: Object Oriented Programming - 2 - Software Development MCQ

Test: Object Oriented Programming - 2 - Software Development MCQ


Test Description

15 Questions MCQ Test - Test: Object Oriented Programming - 2

Test: Object Oriented Programming - 2 for Software Development 2024 is part of Software Development preparation. The Test: Object Oriented Programming - 2 questions and answers have been prepared according to the Software Development exam syllabus.The Test: Object Oriented Programming - 2 MCQs are made for Software Development 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Object Oriented Programming - 2 below.
Solutions of Test: Object Oriented Programming - 2 questions in English are available as part of our course for Software Development & Test: Object Oriented Programming - 2 solutions in Hindi for Software Development course. Download more important topics, notes, lectures and mock test series for Software Development Exam by signing up for free. Attempt Test: Object Oriented Programming - 2 | 15 questions in 30 minutes | Mock test for Software Development preparation | Free important questions MCQ to study for Software Development Exam | Download free PDF with solutions
Test: Object Oriented Programming - 2 - Question 1

Which of the following is not a principle of Object-Oriented Programming (OOP)?

Detailed Solution for Test: Object Oriented Programming - 2 - Question 1

Normalization is not a principle of Object-Oriented Programming (OOP). The correct principles are Inheritance, Encapsulation, and Abstraction.

Test: Object Oriented Programming - 2 - Question 2

Which keyword is used to create an object in C++?

Detailed Solution for Test: Object Oriented Programming - 2 - Question 2

The "new" keyword is used to dynamically allocate memory and create an object in C++.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Object Oriented Programming - 2 - Question 3

In C++, a class is a:

Detailed Solution for Test: Object Oriented Programming - 2 - Question 3

A class in C++ serves as a blueprint for creating objects. It defines the properties (member variables) and behaviors (member functions) that an object of that class can have.

Test: Object Oriented Programming - 2 - Question 4

What is the purpose of a constructor in C++?

Detailed Solution for Test: Object Oriented Programming - 2 - Question 4

Constructors are special member functions in a class that are used to initialize the member variables of an object when it is created.

Test: Object Oriented Programming - 2 - Question 5

Which access specifier allows the members of a class to be accessible from any other class?

Detailed Solution for Test: Object Oriented Programming - 2 - Question 5

The "public" access specifier allows the members of a class to be accessible from any other class.

Test: Object Oriented Programming - 2 - Question 6

What will be the output of the following code?
#include <iostream>

class MyClass {
public:
    int x;

    void display() {
        std::cout << "x = " << x << std::endl;
    }
};

int main() {
    MyClass obj;
    obj.x = 5;
    obj.display();

    return 0;
}

Detailed Solution for Test: Object Oriented Programming - 2 - Question 6

The code creates an object of the class "MyClass" and assigns a value of 5 to the member variable "x". Then, the "display" function is called, which prints the value of "x" as 5.

Test: Object Oriented Programming - 2 - Question 7

What will be the output of the following code?

#include <iostream>

class Base {
public:
    void show() {
        std::cout << "Base class" << std::endl;
    }
};

class Derived : public Base {
public:
    void show() {
        std::cout << "Derived class" << std::endl;
    }
};

int main() {
    Derived d;
    Base* ptr = &d;
    ptr->show();

    return 0;
}

Detailed Solution for Test: Object Oriented Programming - 2 - Question 7

The code creates an object of the class "Derived" and assigns its address to a pointer of type "Base". When the "show" function is called using the pointer, it invokes the function from the derived class, printing "Derived class".

Test: Object Oriented Programming - 2 - Question 8

What will be the output of the following code?
#include <iostream>

class Base {
public:
    virtual void show() {
        std::cout << "Base class" << std::endl;
    }
};

class Derived : public Base {
public:
    void show() {
        std::cout << "Derived class" << std::endl;
    }
};

int main() {
    Derived d;
    Base* ptr = &d;
    ptr->show();

    return 0;
}

Detailed Solution for Test: Object Oriented Programming - 2 - Question 8

The code is similar to the previous question, but the "show" function in the base class is declared as virtual. This enables dynamic polymorphism, so when the function is called through the base class pointer, it invokes the function from the derived class, printing "Derived class".

Test: Object Oriented Programming - 2 - Question 9

What will be the output of the following code?
#include <iostream>

class Base {
public:
    virtual void show() {
        std::cout << "Base class" << std::endl;
    }
};

class Derived : public Base {
public:
    void show() {
        std::cout << "Derived class" << std::endl;
    }
};

int main() {
    Derived d;
    Derived* ptr = &d;
    Base* bptr = ptr;
    bptr->show();

    return 0;
}

Detailed Solution for Test: Object Oriented Programming - 2 - Question 9

The code creates an object of the class "Derived" and assigns its address to a pointer of type "Derived". Then, the pointer is implicitly cast to a base class pointer ("Base* bptr = ptr;"). When the "show" function is called through the base class pointer, it invokes the function from the derived class, printing "Derived class".

Test: Object Oriented Programming - 2 - Question 10

What will be the output of the following code?

#include <iostream>

class Base {
public:
    int x;

    Base() {
        x = 0;
    }

    virtual void display() {
        std::cout << "x = " << x << std::endl;
    }
};

class Derived : public Base {
public:
    Derived() {
        x = 5;
    }

    void display() {
        std::cout << "x = " << x << std::endl;
    }
};

int main() {
    Base* bptr = new Derived();
    bptr->display();

    delete bptr;
    return 0;
}

Detailed Solution for Test: Object Oriented Programming - 2 - Question 10

The code creates a dynamic object of the derived class "Derived" using a base class pointer ("Base* bptr = new Derived();"). When the "display" function is called through the base class pointer, it invokes the overridden function in the derived class, printing "x = 5". The object is properly deallocated using "delete" at the end.

Test: Object Oriented Programming - 2 - Question 11

Which type of inheritance is illustrated in the following code?
class A {
public:
    void foo() {
        std::cout << "A" << std::endl;
    }
};

class B : public A {
public:
    void foo() {
        std::cout << "B" << std::endl;
    }
};

int main() {
    B b;
    b.foo();

    return 0;
}

Detailed Solution for Test: Object Oriented Programming - 2 - Question 11

The code demonstrates single inheritance where class B inherits from class A. The derived class B has a function named "foo" which overrides the function with the same name in the base class A.

Test: Object Oriented Programming - 2 - Question 12

Which statement is true about function overriding in C++?

Detailed Solution for Test: Object Oriented Programming - 2 - Question 12

Function overriding allows a derived class to provide a different implementation of a base class function. It is achieved by declaring a function with the same name and signature in the derived class.

Test: Object Oriented Programming - 2 - Question 13

What is the output of the following code?
#include <iostream>

class A {
public:
    virtual void foo() {
        std::cout << "A" << std::endl;
    }
};

class B : public A {
public:
    void foo() {
        std::cout << "B" << std::endl;
    }
};

int main() {
    A* ptr = new B();
    B* bptr = dynamic_cast<B*>(ptr);
    bptr->foo();

    return 0;
}

Detailed Solution for Test: Object Oriented Programming - 2 - Question 13

The code creates a pointer of type "A*" and assigns the address of a dynamically allocated object of the derived class "B" to it. The pointer is then cast to a "B*" using dynamic_cast. When the "foo" function is called using the derived class pointer, it invokes the function from the derived class, printing "B".

Test: Object Oriented Programming - 2 - Question 14

Which statement is true about pure virtual functions in C++?

Detailed Solution for Test: Object Oriented Programming - 2 - Question 14

A class containing a pure virtual function is called an abstract class. An abstract class cannot be instantiated, meaning objects of the abstract class cannot be created. However, a derived class can inherit from the abstract class and provide implementations for the pure virtual functions.

Test: Object Oriented Programming - 2 - Question 15

Which concept is illustrated in the following code?
class Base {
public:
    virtual void foo() = 0;
};

class Derived : public Base {
public:
    void foo() {
        std::cout << "Derived" << std::endl;
    }
};

int main() {
    Base* ptr = new Derived();
    ptr->foo();

    return 0;
}

Detailed Solution for Test: Object Oriented Programming - 2 - Question 15

The code demonstrates polymorphism by using a base class pointer to invoke a function that is overridden in the derived class. This allows the program to exhibit different behaviors based on the actual object type at runtime. In this case, the "foo" function is invoked through the base class pointer, and it prints "Derived" because the object is of the derived class type.

Information about Test: Object Oriented Programming - 2 Page
In this test you can find the Exam questions for Test: Object Oriented Programming - 2 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Object Oriented Programming - 2, EduRev gives you an ample number of Online tests for practice

Top Courses for Software Development

Download as PDF

Top Courses for Software Development