Escolar Documentos
Profissional Documentos
Cultura Documentos
sanfoundry.com
Answer: c
Explanation: The condition for a class to be called abstract
class is that it must have at least one pure virtual function.
1 of 8 3/19/18, 9:45 AM
Abstract Class - Object Oriented Programming ... about:reader?url=https://www.sanfoundry.com/...
Answer: b
Explanation: This is a property of abstract class. It can
define main() function inside it. There is no restriction on its
definition and implementation.
Answer: a
Explanation: It is a rule that if a class have even one
abstract method, it must be an abstract class. If this rule
was not made, the abstract methods would have got
skipped to get defined in some places which is undesirable
with the idea of abstract class.
2 of 8 3/19/18, 9:45 AM
Abstract Class - Object Oriented Programming ... about:reader?url=https://www.sanfoundry.com/...
abstract is mandatory
b) Implementation of the method in derived class is
mandatory
c) Making the derived class also abstract is mandatory
d) It’s not mandatory to implement the abstract method of
parent class
View Answer
Answer: a
Explanation: Either of the two things must be done, either
implementation or declaration of class as abstract. This is
done to ensure that the method intended to be defined by
other classes gets defined at every possible class.
Answer: d
Explanation: The program runs correctly. This is because
even class B is abstract so it’s not mandatory to define all
the virtual functions. Class C is not abstract but all the
virtual functions have been implemented will that class.
3 of 8 3/19/18, 9:45 AM
Abstract Class - Object Oriented Programming ... about:reader?url=https://www.sanfoundry.com/...
Answer: a
Explanation: When an abstract class is defined, it won’t be
having implementation of at least one function. This will
restrict the class to have any constructor. When the class
doesn’t have constructor, there won’t be any instance of
that class.
Answer: c
Explanation: Even though there can’t be any instance of
abstract class. We can always create pointer or reference
to abstract class. The member functions which have some
implementation inside abstract itself, can be used with
these references.
4 of 8 3/19/18, 9:45 AM
Abstract Class - Object Oriented Programming ... about:reader?url=https://www.sanfoundry.com/...
c) Class definitions
d) Class inheritance
View Answer
Answer: b
Explanation: The abstract classes can be used to create a
generic, extensible class library that can be used by other
programmers. This helps us to get some already
implemented codes and functions that might have not been
provided by the programming language itself.
Answer: b
Explanation: The run time polymorphism is supported by
reference and pointer to an abstract class. This relies upon
base class pointer and reference to select the proper virtual
function.
Answer: a
5 of 8 3/19/18, 9:45 AM
Abstract Class - Object Oriented Programming ... about:reader?url=https://www.sanfoundry.com/...
Answer: a
Explanation: If an abstract class is made final in java, it will
stop the abstract class from being extended. And if the
class is not getting extended, there won’t be any other class
to implement the virtual functions. Due to this contradicting
fact, it can’t be final in java.
Answer: a
Explanation: There is no restriction on declaring static
methods. The only condition is that the virtual functions
must have some definition in program.
6 of 8 3/19/18, 9:45 AM
Abstract Class - Object Oriented Programming ... about:reader?url=https://www.sanfoundry.com/...
Answer: c
Explanation: Derived, parent and static classes can’t have
abstract method (We can’t say what type of these classes
is). And for abstract class it’s not mandatory to have
abstract method. But if any abstract method is there inside
a class, then class must be abstract type.
Answer: d
Explanation: There is no restriction on the number of
abstract classes that can be defined inside a single
program. The programs can use as many abstract classes
as required. But the functions with no body must be
implemented.
7 of 8 3/19/18, 9:45 AM
Abstract Class - Object Oriented Programming ... about:reader?url=https://www.sanfoundry.com/...
Answer: b
Explanation: That is rule of programming language that
each function declared, must have some definition. There
can’t be some abstract method that remains undefined.
Even if it’s there, it would result in compile time error.
8 of 8 3/19/18, 9:45 AM
Template Class - Object Oriented Programming... about:reader?url=https://www.sanfoundry.com/...
sanfoundry.com
Answer: a
Explanation: The template class can support more than one
data type. The only thing is to add all the data types
required in a list separated by comma within template
specification.
1 of 9 3/19/18, 9:46 AM
Template Class - Object Oriented Programming... about:reader?url=https://www.sanfoundry.com/...
b) Template ;
c) template T named(T x, T y){ }
d) Template T1 named(T1 x, T2 y){ }
View Answer
Answer: c
Explanation: The syntax must start with keyword template,
case sensitive. Then it should include the typename and a
variable to denote it. Then whenever that variable is used, it
replaces it with the data type needed.
Answer: b
Explanation: The template class can use default arguments.
This is used to specify the data type to be considered if it is
not specified while passing to the generic class. The default
type will be used.
Answer: d
Explanation: The class specialization is creation of explicit
2 of 9 3/19/18, 9:46 AM
Template Class - Object Oriented Programming... about:reader?url=https://www.sanfoundry.com/...
Answer: c
Explanation: The code reusability is the feature that
becomes more powerful with use of template classes. You
can generate a single code that can be used in variety of
programming situation.
Answer: c
Explanation: The template classes can accept all types of
data types. There is no need to specify the data on which
the class has to operate. Hence it gives us flexibility to code
without worrying about the type of data that might be used
in the code.
3 of 9 3/19/18, 9:46 AM
Template Class - Object Oriented Programming... about:reader?url=https://www.sanfoundry.com/...
Answer: b
Explanation: The I/O specialization is made with wide
character and 8-bit characters. Wide characters are used to
store the characters that might take more than 1 byte of
space in memory or any size that is different from the one
that the machine is using.
Answer: b
Explanation: The typeid() function can be used with the
objects of generic classes. An instance of a template class
will take the type of data that is being used with it. Hence
when typeid() function is used, the data type would have
already been defined and hence we can get desired result
from typeid() function.
4 of 9 3/19/18, 9:46 AM
Template Class - Object Oriented Programming... about:reader?url=https://www.sanfoundry.com/...
Answer: a
Explanation: The string class is more specialized. Since the
string must be able to store any kind of data that is given to
the string. Hence it need maximum specialization.
Answer: c
Explanation: The function overloading is multiple functions
with similar or different functionality but generic class
functions perform the same task on given different types of
data.
5 of 9 3/19/18, 9:46 AM
Template Class - Object Oriented Programming... about:reader?url=https://www.sanfoundry.com/...
Answer: b
Explanation: The generic class have a special case with
static members. Each instance will have its own static
member. The static members are not shared usually.
void main()
{
test<int> (2);
test<int>(2);
test<double>(2.2);
}
a) x = 2 count = 0
x = 2.2 count = 0
6 of 9 3/19/18, 9:46 AM
Template Class - Object Oriented Programming... about:reader?url=https://www.sanfoundry.com/...
x = 2.2 count = 0
b) x = 2 count = 0
x = 2 count = 0
x = 2.2 count = 0
c) x = 2 count = 0
x = 2 count = 1
x = 2.2 count = 0
d) x = 2 count = 0
x = 2 count = 1
x = 2.2 count = 2
View Answer
Answer: c
Explanation: For each new type, the class will have
separate instance. Here two instances will be created and
hence counter for integer goes to 1. And for float value, the
count remains 0 for the output.
Answer: a
Explanation: It is not necessary to use different type with
each call to the generic function. Data may be of same type
with each call but still the function works. We don’t consider
other properties like efficiency with this concept because it
7 of 9 3/19/18, 9:46 AM
Template Class - Object Oriented Programming... about:reader?url=https://www.sanfoundry.com/...
Answer: d
Explanation: There is no restriction on the number of types
to be used for making the class generic. There can be any
number of generic types with a single class. Hence giving
flexibility to code with all the data types.
Answer: b
Explanation: There is no mandatory condition to have static
members inside template class. Not only template, it is not
mandatory to have static members anywhere. We can use
them as required in the code.
8 of 9 3/19/18, 9:46 AM
Template Class - Object Oriented Programming... about:reader?url=https://www.sanfoundry.com/...
9 of 9 3/19/18, 9:46 AM
Base Class - Object Oriented Programming Ques... about:reader?url=https://www.sanfoundry.com/...
sanfoundry.com
Answer: a
Explanation: A class which is parent of another class, or
from which other classes can be derived, is known as a
base class. It is mandatory that a class must have at least
one derived class to be called as a base class.
1 of 7 3/19/18, 9:46 AM
Base Class - Object Oriented Programming Ques... about:reader?url=https://www.sanfoundry.com/...
c) Super
d) Sub
View Answer
Answer: c
Explanation: A class which is being derived by other
classes, is called as super class. This concept is clearly
used in java as we call the functions of a base class by
using the keyword super as required.
Answer: a
Explanation: Every abstract class is a base class. It must be
so, because the functions which are not defined inside the
abstract class, must be defined in the derived classes.
Hence it becomes a base class.
Answer: a
Explanation: In java, multiple inheritance is not supported,
2 of 7 3/19/18, 9:46 AM
Base Class - Object Oriented Programming Ques... about:reader?url=https://www.sanfoundry.com/...
which leads to the fact that a class can have only 1 parent
class if inheritance is used. Only if interfaces are used then
the class can implement more than one base class.
Answer: c
Explanation: Making another class derive from it will make
that class as base class. It is not necessary that we have to
write a different code for it. If at least one class derives that
class, it becomes the base class for the new class.
Answer: d
Explanation: When more than one classes are being
derived from a single parent class, the inheritance is known
as hierarchical inheritance. This is usually useful when the
base class is higher abstraction of its derived classes.
3 of 7 3/19/18, 9:46 AM
Base Class - Object Oriented Programming Ques... about:reader?url=https://www.sanfoundry.com/...
b) Member functions
c) Access specifiers
d) Nothing
View Answer
Answer: d
Explanation: Even a class which doesn’t have any members
can be a base class. It is not mandatory to have any
member or attribute in base class.
Answer: b
Explanation: The private members can be accessed only
inside the base class. If the class is derived by other
classes. Those members will not be accessible. This
concept of OOP is made to make the members more
secure.
Answer: b
Explanation: When a class have more than one nested
4 of 7 3/19/18, 9:46 AM
Base Class - Object Oriented Programming Ques... about:reader?url=https://www.sanfoundry.com/...
Answer: b
Explanation: A base class will have lesser information as
compared to those of derived classes. Since derived
classes inherit the base class properties and then add on
their own features, they elaborate more hence have lower
degree of abstraction.
Answer: a
Explanation: When the base class object is created, its
constructor will be called for sure. But if derived class
constructor is called, first base class constructor is called
and then derived class constructor is taken into
consideration.
5 of 7 3/19/18, 9:46 AM
Base Class - Object Oriented Programming Ques... about:reader?url=https://www.sanfoundry.com/...
Answer: a
Explanation: If the function is defined in the base class, it
can always be called from the constructor of its derived
class. Since the constructors are not private, they can be
accessed in derived class even if those are protected.
Answer: d
Explanation: If a base class is inherited from another class,
single inheritance is shown. But when one more class
inherits the derived class, this becomes a multi-level
inheritance.
6 of 7 3/19/18, 9:46 AM
Base Class - Object Oriented Programming Ques... about:reader?url=https://www.sanfoundry.com/...
d) As many as required
View Answer
Answer: d
Explanation: This is because C++ allows the multiple
inheritance. A derived class can have more than one base
class and hence can derive all of their features.
Answer: b
Explanation: The base class can be added with new
members without affecting the sub classes. This is because
the sub classes may get some more features inherited but it
won’t use them. But the base class will be able to use the
new members as would be required.
7 of 7 3/19/18, 9:46 AM
Derived Class - Object Oriented Programming ... about:reader?url=https://www.sanfoundry.com/...
sanfoundry.com
Answer: b
Explanation: Any class which inherits one or more classes
is a derived class. The only condition is it must inherit at
least one class in order to be called as a derived class.
1 of 8 3/19/18, 9:46 AM
Derived Class - Object Oriented Programming ... about:reader?url=https://www.sanfoundry.com/...
Answer: c
Explanation: The class inheriting another class, inherits all
the data members and member functions which are not
private. This is done to ensure the security features with
maximum flexibility.
Answer: b
Explanation: If there is a derived class in a program, there
must be at least 2 classes in that program. One is a base
class and another derived class. Hence at least 2 classes
must be there.
2 of 8 3/19/18, 9:46 AM
Derived Class - Object Oriented Programming ... about:reader?url=https://www.sanfoundry.com/...
Answer: d
Explanation: There is no restriction for a derived class to
access the members of the base class until and unless the
members are private. Private member are declared so that
those members are not accessible outside the class.
Answer: c
Explanation: There are three types of inheritance possible.
Private inheritance, protected inheritance, and public
inheritance. The inheritance defines the access specifier to
be used with the inherited members in the derived class.
Answer: d
Explanation: There is no restriction on how many classes
can inherit a single base class. Hence there can be as
many derived classes as required in a program from a
single base class.
3 of 8 3/19/18, 9:46 AM
Derived Class - Object Oriented Programming ... about:reader?url=https://www.sanfoundry.com/...
Answer: a
Explanation: The friend function of a class can access the
non-private members of base class. The reason behind is
that the members of base class gets derived into the
derived class and hence become members of derived class
too. Hence a friend function can access all of those.
Answer: d
Explanation: The statement given is definition of multiple
inheritance with respect to the derived class. The concept
can be illustrated with many other samples but the main
aspects are base class and derived class only.
4 of 8 3/19/18, 9:46 AM
Derived Class - Object Oriented Programming ... about:reader?url=https://www.sanfoundry.com/...
Answer: a
Explanation: It is just another name given to the derived
classes. This is used while denoting all the derived classes
subsequent to a super class.
Answer: c
Explanation: The abstraction level of class C will be
maximum. This is because the parent class have higher
level of abstraction. Hence the parent of all other class will
have maximum level of abstraction.
5 of 8 3/19/18, 9:46 AM
Derived Class - Object Oriented Programming ... about:reader?url=https://www.sanfoundry.com/...
Answer: b
Explanation: The function must be defined in the program
which are not defined in the base class. Hence the class
must be defined as abstract of implement the function
definition in it.
Answer: d
Explanation: When a class is to be derived from another
derived class, the derived class behaves as a normal base
class hence there are no restriction on how many class can
be derived from a derived class. The derived class again
behaves as a normal super class.
Answer: b
Explanation: This is not true that the members of a derived
class can’t be derived. All the classes are considered to be
a normal class when used for derivation. The members can
6 of 8 3/19/18, 9:46 AM
Derived Class - Object Oriented Programming ... about:reader?url=https://www.sanfoundry.com/...
Answer: c
Explanation: The memory management is the feature that is
not necessary for derived classes that will be a part of
whole program. The functions references must be resolved
for their proper use if inheritance is used.
15. Deriving a class in such a way that that the base class
members are not available for further inheritance is known
as ___________________
a) Public inheritance
b) Protected inheritance
c) Protected or private inheritance
d) Private inheritance
View Answer
Answer: d
Explanation: The private members of a class can never be
derived to another class. When a class derives another
class using private inheritance, all the members become
private members of the derived class. Hence these member
won’t be available for further inheritance.
7 of 8 3/19/18, 9:46 AM
Derived Class - Object Oriented Programming ... about:reader?url=https://www.sanfoundry.com/...
8 of 8 3/19/18, 9:46 AM
Class Use - Object Oriented Programming Ques... about:reader?url=https://www.sanfoundry.com/...
sanfoundry.com
Answer: b
Explanation: The classes are made to encapsulate the data
and properties that are most similar and can be grouped
together inside a single class. This single class can
represent all of those features by creating its instances.
1 of 8 3/19/18, 9:46 AM
Class Use - Object Oriented Programming Ques... about:reader?url=https://www.sanfoundry.com/...
b) Structure
c) Function
d) Object
View Answer
Answer: a
Explanation: A class can be used to group all the brands of
cars. The Different brands may have different properties but
all will have some common properties like number of
wheels and doors, accessories etc. All of those properties
can be grouped into a single class representing all the cars.
Answer: b
Explanation: The best choice would be to define a public
member function that returns the values of two data
members of the class. This way we can implement any
operation on those data members. Also there won’t be any
need to modify the program and to add new functions for
each new operation.
2 of 8 3/19/18, 9:46 AM
Class Use - Object Oriented Programming Ques... about:reader?url=https://www.sanfoundry.com/...
Answer: a
Explanation: A single class can be defined that represents a
single employee of a company. The specific type of
functions that can be applied to specific employees can be
put into another class that is derived from the existing class.
Answer: d
Explanation: The base classes are the most abstracted part
of information. A base class having many other derived
classes would have a bigger overview of all the other
derived classes. Hence the base classes have the most
abstract information.
3 of 8 3/19/18, 9:46 AM
Class Use - Object Oriented Programming Ques... about:reader?url=https://www.sanfoundry.com/...
Answer: c
Explanation: The functions are also made easy to be
encapsulated inside a class. In structures, only the data
members were allowed to be encapsulated. Hence classes
can represent an entity in a better way.
Answer: a
Explanation: Thee use of classes feature the object
oriented programming. The OOP concept can be
implemented by using class and their objects. Procedures
orientation is not feature of OOP.
Answer: c
Explanation: The class is an overview for an object. It
4 of 8 3/19/18, 9:46 AM
Class Use - Object Oriented Programming Ques... about:reader?url=https://www.sanfoundry.com/...
Answer: c
Explanation: The classes would be more suitable to use in
case where we need to group the most similar data and
operations. The data can be represented as data members
of class and operations as member functions of class. This
is indirectly encapsulation feature.
Answer: c
Explanation: The data that is constant or is always the
same initially for use can be provided by some inbuilt
classes. The functions that are mostly used are also
provided by the inbuilt classes. The data and functions can
be used by including the corrosponding header file or
library.
5 of 8 3/19/18, 9:46 AM
Class Use - Object Oriented Programming Ques... about:reader?url=https://www.sanfoundry.com/...
Answer: d
Explanation: The code is reusable as the functions which
are already written, can be used anytime required. The
code becomes easier to read. Also, the code is efficient as
there is no need to assign any external code.
Answer: b
Explanation: The primitive classes are not sufficient for the
programming complex algorithms. Some user defined
classes are required to represent a real world object and to
define a blueprint of what the class should actually contain.
The user defined classes are as per the requirements and
need of user.
6 of 8 3/19/18, 9:46 AM
Class Use - Object Oriented Programming Ques... about:reader?url=https://www.sanfoundry.com/...
Answer: d
Explanation: The private data of a class is usually not
accessible. But the data can be accessed by the user using
accessor functions. These functions allows the user to get
the data stored as private in a class.
Answer: b
Explanation: The client can have rights to access a file and
write something to it. This is mandatory to keep the private
data updated. Also it is an advantage over the use of
hidden class members.
Answer: a
Explanation: The most abstract class is class Cars. The
class Cars is most general form of all other cars. If it is a
7 of 8 3/19/18, 9:46 AM
Class Use - Object Oriented Programming Ques... about:reader?url=https://www.sanfoundry.com/...
8 of 8 3/19/18, 9:46 AM