Back-End Programming

Which is called on allocating the memory for array of objects?
  • a)
    destructor
  • b)
    constructor
  • c)
    method
  • d)
    None of the mentioned
Correct answer is option 'B'. Can you explain this answer?

SARITA HANS answered  •  Sep 12, 2020
When you allocate memory for an array of objects, the default constructor must be called to construct each object. If no default constructor exists, you’re stuck needing a list of pointers to objects.

Which of the following cannot be passed to a function in C++ ?
  • a)
    Constant
  • b)
    Structure
  • c)
    Array
  • d)
    Header file
Correct answer is option 'D'. Can you explain this answer?

SHAILZA THAKUR answered  •  Apr 20, 2020
Header file can not be passed to a function in C++. While array, constant and structure can be passed into a function.
So, option (D) is correct.

Which of the following is true?
  • a)
    All objects of a class share all data members of class
  • b)
    Objects of a class do not share non-static members. Every object has its own copy.
  • c)
    Objects of a class do not share codes of non-static methods, they have their own copy
  • d)
    None of the above
Correct answer is option 'B'. Can you explain this answer?

SHALINI THAKUR answered  •  Apr 20, 2020
Every object maintains a copy of non-static data members. For example, let Student be a class with data members as name, year, batch. Every object of student will have its own name, year and batch. On a side note, static data members are shared among objects.
All objects share codes of all methods. For example, every student object uses same logic to find out grades or any other method.

What can be passed by non-type template parameters during compile time?
  • a)
    int
  • b)
    float
  • c)
    constant expression
  • d)
    none of the mentioned
Correct answer is option 'C'. Can you explain this answer?

SURBHI CHADDA answered  •  Apr 20, 2020
Non-type template parameters provide the ability to pass a constant expression at compile time. The constant expression may also be an address of a function, object or static class member.

Predict the output of following C++ program
#include<iostream>
using namespace std;
  
class Empty {};
  
int main()
{
  cout << sizeof(Empty);
  return 0;
}
  • a)
    A non-zero value
  • b)
    0
  • c)
    Compiler Error
  • d)
    Runtime Error
Correct answer is option 'A'. Can you explain this answer?

SUNITA DEVI answered  •  Apr 20, 2020
#include<iostream>
using namespace std;
  
class Empty {};
  
int main()
{
  cout << sizeof(Empty);
  return 0;
}
Output : 1
Size of an empty class is not zero. It is 1 byte generally. It is nonzero to ensure that the two different objects will have different addresses. 

Which of the following is not a correct statement?
  • a)
    Every class containing abstract method must be declared abstract.
  • b)
    Abstract class can directly be initiated with ‘new’ operator.
  • c)
    Abstract class can be initiated.
  • d)
    Abstract class does not contain any definition of implementation.
Correct answer is option 'B'. Can you explain this answer?

VANDANA CHANDEL answered  •  Apr 20, 2020
• Every class containing abstract method must be declared abstract. Correct Declaration is required.
• Abstract class can directly be initiated with ‘new’ operator. No it can’t be initiated directed by only ‘new’ operator. So, it is Inorrect
• Abstract class can be initiated. Correct
• Abstract class does not contain any definition of implementation. Correct
So, option (B) is correct.

Which operator is used to create the user-defined streams in c++?
  • a)
    >>
  • b)
    &
  • c)
    Both a & b
  • d)
    None of  these
Correct answer is option 'C'. Can you explain this answer?

ABHISHEK MAAN answered  •  Apr 20, 2020
We can make user-defined types with streams by overloading the insertion operator (<<) to put objects into streams and the extraction operator (>>) to read objects from streams.

When a method in a subclass has the same name and type signatures as a method in the superclass, then the method in the subclass _____ the method in the superclass.
  • a)
    Overloads
  • b)
    Friendships
  • c)
    Inherits
  • d)
    Overrides
Correct answer is option 'D'. Can you explain this answer?

ASHUTOSH KAUSHIK answered  •  Apr 20, 2020
• When a method in a subclass has the same name and type signatures as a method in the superclass, then the method in the subclass overrides the method in the superclass.
• Overloading allows different methods to have same name, but different signatures where signature can differ by number of input parameters or type of input parameters or both. Overloading is related to compile time (or static) polymorphism..
• Friend Class A friend class can access private and protected members of other class in which it is declared as friend..
• The capability of a class to derive properties and characteristics from another class is called Inheritance.
So, option (D) is correct.

It is possible to define a class within a class termed as nested class. There are _____ types of nested classes.
  • a)
    2
  • b)
    3
  • c)
    4
  • d)
    5
Correct answer is option 'A'. Can you explain this answer?

ABHINAND S answered  •  Apr 20, 2020
It is possible to define a class within a class termed as nested class. There are two types of nested classes.
1 – Outer class will use argument of inner class.
2 – Inner and outer class are independent to each other.(different argument)
So, optioin (A) is correct.

A member function can always access the data in __________ , (in C++).
  • a)
    The class of which it is member
  • b)
    The object of which it is a member
  • c)
    The public part of its class
  • d)
    The private part of its class
Correct answer is option 'A'. Can you explain this answer?

BINIT YADAV answered  •  Apr 19, 2020
A member function can access it’s class member variables, irrespective of the access specifier in which the member variable is declared.So, a member function can always access the data in the class of which it is a member.
So, option (A) is correct.

Which of the following is not correct (in C++) ?
1. Class templates and function templates are instantiated in the same way
2. Class templates differ from function templates in the way they are initiated
3. Class template is initiated by defining an object using the template argument
4. Class templates are generally used for storage classes
  • a)
    1
  • b)
    2, 4
  • c)
    2, 3, 4
  • d)
    4
Correct answer is option 'C'. Can you explain this answer?

RAVNEET SINGH answered  •  Apr 19, 2020
In C++ class template and function template are similar in the way the are initiated.
Class template are not used for storage class. Class templates and function templates are instantiated in the same way and Class template is not initiated by defining an object using the template.
So (2), (3), (4) are not correct in C++.
So, option (C) is correct.

What is the use of clog?
  • a)
    Standard logging stream
  • b)
    Error stream
  • c)
    Input stream
  • d)
    None of the mentioned
Correct answer is option 'A'. Can you explain this answer?

AMIT PANDEY answered  •  Apr 19, 2020
Clog is an object of class ostream that represents the standard logging stream. It is associated with the cstdio stream stderr, like cerr.

Which of the following, in C++, is inherited in a derived class from base class ?
  • a)
    Constructor
  • b)
    Destructor
  • c)
    Data members
  • d)
    Virtual methods
Correct answer is option 'C'. Can you explain this answer?

KARTIK KANT answered  •  Apr 19, 2020
• Data members in C++ is inherited in a derived class from base class
• Constructor is a member function of a class which initializes objects of a class. In C++,Constructor is automatically called when object(instance of class) create.It is special member function of the class.
• Destructor is a member function which destructs or deletes an object.
• Virtual methods is a method which is redefined(Over-riden) in derived class.
So, option (C) is correct.

Which of the following is a correct statement?
  • a)
    Composition is a strong type of association between two classes with full ownership.
  • b)
    Composition is a strong type of association between two classes with partial ownership.
  • c)
    Composition is a weak type of association between two classes with partial ownership.
  • d)
    Composition is a weak type of association between two classes with strong ownership.
Correct answer is option 'A'. Can you explain this answer?

NAMAN AGGARWAL answered  •  Apr 19, 2020
• Composition is a strong type of association between two classes with full ownership. Correct.
• Composition is a strong type of association between two classes with partial ownership. Incorrect
• Composition is a weak type of association between two classes with partial ownership. Incorrect
• Composition is a weak type of association between two classes with strong ownership. Incorrect
So, option (A) is correct.

#include <stdio.h>
 
int main()
{
    int a[][] = {{1,2},{3,4}};
    int i, j;
    for (i = 0; i < 2; i++)
        for (j = 0; j < 2; j++)
            printf("%d ", a[i][j]);
    return 0;
}
  • a)
    1 2 3 4
  • b)
    Compiler Error in line " int a[][] = {{1,2},{3,4}};"
  • c)
    4 garbage values
  • d)
    4 3 2 1
Correct answer is option 'B'. Can you explain this answer?

MANOHAR SINGH answered  •  Apr 19, 2020
There is compilation error in the declaration " int a[][] = {{1,2},{3,4}};". Except the first dimension, every other dimension must be specified.
int arr[] = {5, 6, 7, 8} //valid
int arr[][5] = {}; //valid
int arr[][] = {}; //invalid
int arr[][10][5] = {}; //valid
int arr[][][5] = {}; //invalid

Which parameter is legal for non-type template?
  • a)
    pointer to member
  • b)
    object
  • c)
    class
  • d)
    none of the mentioned
Correct answer is option 'A'. Can you explain this answer?

SARTHAK SAHU answered  •  Apr 19, 2020
The following are legal for non-type template parameters:integral or enumeration type, Pointer to object or pointer to function, Reference to object or reference to function, Pointer to member.

Fetching relevant content for you
Ask a question