Object Oriented MCQ Set 1
1. What is downcasting?
a) Casting subtype to supertype
b) Casting supertype to subtype
c) Casting subtype to super type and vice versa
d) Casting anytype to any other type
Answer
Answer: b [Reason:] The downcasting concept includes only the casting of supertypes to the sub types. This casting is generally done explicitly. Larger size types are made to fit into small size types explicitly.
2. Which among the following is a mandatory condition for downcasting?
a) It must not be done explicitly
b) It must be done implicitly
c) It must be done explicitly
d) It can’t be done explicitly
Answer
Answer: c [Reason:] The downcasting of any object must be done explicitly. This is because the compilers don’t support the implicit conversion of a super type to sub type.
3. Downcasting is _______
a) Always safe
b) Never safe
c) Safe sometimes
d) Safe, depending on code
Answer
Answer: b [Reason:] The downcasting concept is made for exception cases. When there is a need to represent an entity in the form which is not suitable for it. Representing a base type in derived type is not right but can be done for special cases.
4. Downcasting ____
a) Can result in unexpected results
b) Can’t result in unexpected result
c) Can result only in out of memory error
d) Can’t result in any error
Answer
Answer: a [Reason:] The result of downcasting can be unexpected. This is because downcasting is done on the objects into the objects which doesn’t contain any information of data in lateral object.
5. What should be used for safe downcast?
a) Static cast
b) Dynamic cast
c) Manual cast
d) Implicit cast
Answer
Answer: b [Reason:] The dynamic cast can be done using the operator dynamic_cast. This converts one type to another type in safe way.
6. What does dynamic_cast return after successful type casting?
a) Address of object which is converted
b) Address of object that is used for conversion
c) Address of object that is mentioned in the syntax
d) Doesn’t return any address
Answer
Answer: a [Reason:] The address of the object which is converted is returned by the dynamic_cast operator. This is done to safely convert the subtype to supertype. This ensure the proper assignment and conversion from one type to another.
7. If dynamic_cast fails, which value is returned?
a) void
b) null
c) void pointer
d) null pointer
Answer
Answer: d [Reason:] The null pointer is returned by the dynamic_cast, if it fails. The conversion sometimes fails because of too complex type conversion. The conversion may also fail due to memory or some related issues.
8. Which is the proper syntax of dynamic_cast?
a) dynamic_cast(object)
b) dynamic_cast new (object)
c) dynamic_cast
d) dynamic_cast(object)
Answer
Answer: c [Reason:] The dynamic_cast is the name of operator, which is followed by the new type in which the object have to be converted. Then the object name is given. This object name is then used after the type conversion.
9. Which is the exception handler for the exceptions of downcasting?
a) CastException
b) ClassCastingExeption
c) ClassCasting
d) ClassCastException
Answer
Answer: d [Reason:] The exception handler for the exceptions produced during the downcasting exception. This hander can be called during runtime to handle any exception thrown.
10. How to prevent the ClassCastExceptions?
a) By using instanceof
b) By using is-a check
c) By using arrow operator with check function
d) By checking type of conversion
Answer
Answer: a [Reason:] The instanceof operator can be used to check the compatibility of the conversion. This has to be done to check whether the casting would be safe or not.
11. Java supports direct downcasting.
a) True
b) False
Answer
Answer: b [Reason:] The downcasting is not possible in java directly. This has to be done explicitly. The downcasting is not safe but can be checked for safe casting using instanceof function.
12. Which way the downcasting is possible with respect to inheritance?
a) Upward the inheritance order
b) Downward the inheritance order
c) Either upward or downward the inheritance order
d) Order of inheritance doesn’t matter
Answer
Answer: b [Reason:] The downcasting is always downward the inheritance order. Since the base class object have to be casted into derived class type. This is basic definition of downcasting.
13. What happens when downcasting is done but not explicitly defined in syntax?
a) Compiler time error
b) Run time error
c) Code write time error
d) Conversion error
Answer
Answer: a [Reason:] The implicit downcasting is not possible. If tried, the compiler produces an error. Since the compiler doesn’t allow coasting to a type which is not compatible.
14. When is downcating used?
a) To separate inherited class from base class
b) To write a more complex code
c) To compare two objects
d) To disable one class in inheritance
Answer
Answer: c [Reason:] The downcasting can be used whenever there is a need to compare one object to another. Equals() function can be used to compare whether the objects were of same age. We can use getClass() function too.
15. Why is downcasting possible in any language?
a) Because inheritance follows has-a relationship
b) Because inheritance follows is-a relationship
c) Because inheritance doesn’t follow any relationship
d) Because inheritance is not involved in casting
Answer
Answer: b [Reason:] The downcasting is possible because the classes in inheritance follow is-a relationship. Hence the derived class is a base class. Which in turn make the downcasting possible.
Object Oriented MCQ Set 2
1. Which among the following best describes encapsulation?
a) It is a way of combining various data members into a single unit
b) It is a way of combining various member functions into a single unit
c) It is a way of combining various data members and member functions into a single unit which can operate on any data
d) It is a way of combining various data members and member functions that operate on those data members into a single unit
Answer
Answer: d [Reason:] It is a way of combining both data members and member functions, which operate on those data members, into a single unit. We call it a class in OOP generally. This feature have helped us modify the structures used in C language to be upgraded into class in C++ and other languages.
2. If data members are private, what can we do to access them from the class object?
a) Create public member functions to access those data members
b) Create private member functions to access those data members
c) Create protected member functions to access those data members
d) Private data members can never be accessed from outside the class
Answer
Answer: a [Reason:] We can define public member functions to access those private data members and get their value for use or alteration. They can’t be accessed directly but is possible to be access using member functions. This is done to ensure that the private data doesn’t get modified accidently.
3. While using encapsulation, which among the following is possible?
a) Code modification can be additional overhead
b) Data member’s data type can be changed without changing any other code
c) Data member’s type can’t be changed, or whole code have to be changed
d) Member functions can be used to change the data type of data members
Answer
Answer: b [Reason:] Data member’s data type can be changed without changing any further code. All the members using that data can continue in the same way without any modification. Member functions can never change the data type of same class data members.
4. Which feature can be implemented using encapsulation?
a) Inheritance
b) Abstraction
c) Polymorphism
d) Overloading
Answer
Answer: b [Reason:] Data abstraction can be achieved by using encapsulation. We can hide the operation and structure of actual program from the user and can show only required information by the user.
5. Find which of the following uses encapsulation?
a) void main(){ int a; void fun( int a=10; cout<<a); fun(); }
b) class student{ int a; public: int b;};
c) class student{int a; public: void disp(){ cout<<a;} };
d) struct topper{ char name[10]; public : int marks; }
Answer
Answer: c [Reason:] It is the class which uses both the data members and member functions being declared inside a single unit. Only data members can be there in structures also. And the encapsulation can only be illustrated if some data/operations are associated within class.
6. Encapsulation helps in writing _____ classes in java
a) Mutable
b) Abstract
c) Wrapper
d) Immutable
Answer
Answer: d [Reason:] Immutable classes are used for caching purpose generally. And it can be created by making the class as final and making all its members private.
7. Which among the following should be encapsulated?
a) The data which is prone to change is near future
b) The data prone to change in long terms
c) The data which is intended to be changed
d) The data which belongs to some other class
Answer
Answer: a [Reason:] The data prone to change in near future is usually encapsulated so that it doesn’t get changed accidently. We encapsulate the data to hide the critical working of program from outside world.
8. How can Encapsulation be achieved?
a) Using Access Specifiers
b) Using only private members
c) Using inheritance
d) Using Abstraction
Answer
Answer: a [Reason:] Using access specifiers we can achieve encapsulation. Using this we can in turn implement data abstraction. It’s not necessary that we only use private access.
9. Which among the following violates the principle of encapsulation almost always?
a) Local variables
b) Global variables
c) Public variables
d) Array variables
Answer
Answer: b [Reason:] Global variables almost always violates the principles of encapsulation. Encapsulation says the data should be accessed only by required set of elements. But global variable is accessible everywhere, also it is most prone to changes. It doesn’t hide the internal working of program.
10. Which among the following would destroy the encapsulation mechanism if it was allowed in programming?
a) Using access declaration for private members of base class
b) Using access declaration for public members of base class
c) Using access declaration for local variable of main() function
d) Using access declaration for global variables
Answer
Answer: a [Reason:] If using access declaration for private members of base class was allowed in programming, it would have destroyed whole concept of encapsulation. As if it was possible, any class which gets inherited privately, would have been able to inherit the private members of base class, and hence could access each and every member of base class.
11. Which among the following can be a concept against encapsulation rules?
a) Using function pointers
b) Using char* string pointer to be passed to non-member function
c) Using object array
d) Using any kind of pointer/array address in passing to another function
Answer
Answer: d [Reason:] If we use any kind of array or pointer as data member which should not be changed, but in some case its address is passed to some other function or similar variable. There are chances to modify its whole data easily. Hence Against encapsulation.
12. Consider the following code and select the correct option:
class student { int marks; public : int* fun() { return &marks; } }; main() { student s; int *ptr=c.fun(); return 0; }
a) This code is good to go
b) This code may result in undesirable conditions
c) This code will generate error
d) This code violates encapsulation
Answer
Answer: d [Reason:] This code violates the encapsulation. By this code we can get the address of the private member of the class, hence we can change the value of private member, which is against the rules.
13. Consider the code and select the wrong choice:
class hero { char name[10]; public : void disp() { cout<<name; } };
a) This maintains encapsulation
b) This code doesn’t maintain encapsulation
c) This code is vulnerable
d) This code gives error
Answer
Answer: a [Reason:] This code maintains encapsulation. Here the private member is kept private. Outside code can’t access the private members of class. Only objects of this class will be able to access the public member function at maximum.
14. Encapsulation is the way to add functions in a user defined structure.
a) True
b) False
Answer
Answer: b [Reason:] False, because we can’t call these structures if member functions are involved, it must be called class. Also, it is not just about adding functions, it’s about binding data and functions together.
15. Using encapsulation data security is _____
a) Not ensured
b) Ensured to some extent
c) Purely ensured
d) Very low
Answer
Answer: b [Reason:] The encapsulation can only ensure the data security to some extent. If pointer and addresses are misused, it may violate encapsulation. Use of global variables also makes the program vulnerable, hence we can’t say that encapsulation gives pure security.
Object Oriented MCQ Set 3
1. Virtual function is ______ class function which expected to be redefined in ______ class, so that when reference is made to derived class object using pointer then we can call virtual function to execute ________ class definition version.
a) Base, derived, derived
b) Derived, Derived, Derived
c) Base, derived, base
d) Base, base, derived
Answer
Answer: a [Reason:] The functions which may give rise to ambiguity due to inheritance, can be declared virtual. So that whenever derived class object is referred using pointer or reference to the base class methods, we can still call the derived class methods using virtual function. Hence this differentiates those methods from each other.
2. What does a virtual function ensure for an object, among the following?
a) Correct method is called, regardless of the class defining it
b) Correct method is called, regardless of the object being called
c) Correct method is called, regardless of the type of reference used for function call
d) Correct method is called, regardless of the type of function being called by objects
Answer
Answer: c [Reason:] It is property of the virtual function and one of their main use. Its use ensure that the correct method is called even though it is been called from different pointer or references. This also decreases chance of mistakes in program.
3. Virtual functions are mainly used to achieve _______
a) Compile time polymorphism
b) Interpreter polymorphism
c) Runtime polymorphism
d) Functions code polymorphism
Answer
Answer: c [Reason:] It is used to achieve runtime polymorphism. The functions which are inherited and overridden, so at runtime the correct function is executed. The correct function call is made from the intended class.
4. Which keyword is used to declare virtual functions?
a) virtual
b) virt
c) anonymous
d) virtually
Answer
Answer: a [Reason:] The virtual keyword is used to declare virtual functions. Anonymous keyword is used with classes and have a different meaning. The virtual functions are used to call the intended function of derived class.
5. Where the virtual function should be defined?
a) Twice in base class
b) Derived class
c) Base class and derived class
d) Base class
Answer
Answer: d [Reason:] The virtual function should be declared in base class. So that when the derived class inherits from the base class, the functions can be differentiated from the one in base class and another in derived class.
6. The resolving of virtual functions is done at ________
a) Compile time
b) Interpret time
c) Runtime
d) Writing source code
Answer
Answer: c [Reason:] The resolving of virtual functions which are to be called is done at run time. The base class and the derived classes may contain different definitions and different variables, so all these things are resolved at run time and decided which function is to be called.
7. In which access specifier should a virtual function be defined?
a) Private
b) Public
c) Protected
d) Default
Answer
Answer: b [Reason:] The virtual functions must be defined in public section of a class. This is to ensure that the virtual function is available everywhere in the program. Also to avoid any error while resolving the method.
8. Virtual functions can never be made ___
a) Static function
b) Parameterized function
c) Default argument function
d) Zero parameter function
Answer
Answer: a [Reason:] The virtual function must not be static. Those functions are property of individual objects and not of a class as a whole. The functions should not be made common for all the objects of that class.
9. Virtual functions can’t be made friend function of other classes.
a) True
b) False
Answer
Answer: a [Reason:] The friend functions can access the private members also. This may hinder the security of class members. This is why the functions should not be made friend functions of other class.
10. Which is must condition for virtual function to achieve runtime polymorphism?
a) Virtual function must be accessed with direct name
b) Virtual functions must be accessed using base class object
c) Virtual function must be accessed using pointer or reference
d) Virtual function must be accessed using derived class object only
Answer
Answer: c [Reason:] The virtual functions must be called using pointer or reference. This is mandatory so that the intended function gets executed while resolving the method at runtime. The must not be any ambiguity between the method of parent class and derived class.
11. Which among the following is true for virtual functions?
a) Prototype must be different in base and derived class
b) Prototype must be same in base class and derived class
c) Prototype must be given only in base class
d) Prototype must have different signature in base and derived class
Answer
Answer: b [Reason:] The prototype must be the same. Because the function is to be overridden in the derived class. If the function prototype is different in derived class then it will not override the base class function and hence virtual function concept won’t work here.
12. The virtual functions must be declared and defined in _______ class and overridden in _____ class.
a) Base, base
b) Derived, derived
c) Derived, base
d) Base, derived
Answer
Answer: d [Reason:] The virtual functions must be declared and defined in base class. The functions can be redefined in derived class. If redefined in derived class then it overrides the base class function definition.
13. It is ____ to redefine the virtual function in derived class?
a) Necessary
b) Not necessary
c) Not acceptable
d) Good practice
Answer
Answer: b [Reason:] It is not necessary to redefine the virtual function in derived class. If not defined, the base class function definition is used but if defined, the intended definition is used according to need. It is not about good coding practice as it should be redefined only if needed.
14. Which among the following is true?
a) A class may have virtual destructor but not virtual constructor
b) A class may have virtual constructor but not virtual destructor
c) A class may have virtual constructor and virtual constructor
d) A class may have either virtual destructor or virtual constructor
Answer
Answer: a [Reason:] Any class can contain virtual destructor. But is not possible to define a virtual constructor. The reason behind is that the destructors can be overridden but constructors should not be.
15. If virtual function of base class is redefined in derived class then, ________
a) It must be declared virtual in derived class also
b) It may or may not be declared virtual in derived class
c) It can must not be declared virtual in derived class
d) It must be declared normally in derived class
Answer
Answer: b [Reason:] The virtual functions may or may not be declared virtual in derived class. This is because if the overriding function defined in derived class is not declared virtual explicitly, the compiler makes it virtual implicitly.
Object Oriented MCQ Set 4
1. What is an exception?
a) Problem arising during compiler time
b) Problem arising during runtime
c) Problem in syntax
d) Problem in IDE
Answer
Answer: b [Reason:] The problems that might occur during execution of a program are known as exceptions. The exceptions are unexpected sometimes and can be predicted. Also, the exceptions should be always considered for a better program.
2. Why do we need to handle exceptions?
a) To prevent abnormal termination of program
b) To encourage exception prone program
c) To avoid syntax errors
d) To save memory
Answer
Answer: a [Reason:] The exceptions should be handled to prevent any abnormal termination of a program. The program should keep running even if it gets interrupted in between. The program should preferable show the error occurred and then retry the process or just continue the program further.
3. An exception may arise when ___
a) Input is fixed
b) Input is some constant value of program
c) Input given is invalid
d) Input is valid
Answer
Answer: c [Reason:] The exceptions may arise because the input given by the user might not be of the same type that a program can manage. If the input is invalid the program gets terminated.
4. If a file that needs to be opened is not found in the target location then _______
a) Exception will be produced
b) Exceptions are not produced
c) Exception might get produced because of syntax
d) Exceptions are not produced because of logic
Answer
Answer: a [Reason:] The exceptions are produced when anything unexpected happened. The program might not be able to find a file in the target location and hence program produces an exceptions. The exception produced, then terminates the program.
5. Which is the universal exception handler class?
a) Object
b) Math
c) Errors
d) Exceptions
Answer
Answer: d [Reason:] Any type of exception can be handled by using class Exceptions. An object of this class is created which can manipulate the exception data. The data can be used to display the error or to run the program further based on error produced.
6. What are two exception classes in hierarchy of java exceptions class?
a) Runtime exceptions only
b) Compile time exceptions only
c) Runtime exceptions and other exceptions
d) Other exceptions
Answer
Answer: c [Reason:] The exceptions class is having two other derived classes which are of runtime exception handler and for other type of exceptions handling. The runtime exception handler is used to handle the exceptions produced during run time and same with case of other exceptions.
7. Which are the two blocks that are used to check error and handle the error?
a) Try and catch
b) Trying and catching
c) Do and while
d) TryDo and Check
Answer
Answer: a [Reason:] Two blocks that are used to check for errors and to handle the errors are try and catch block. The code which might produce some exceptions is placed inside the try block and then the catch block is written to catch the error that is produced. The error message or any other processing can be done in catch block if the error is produced.
8. There can be a try block without catch block but vice versa is not possible.
a) True
b) False
Answer
Answer: a [Reason:] The try block may or may not have any catch block. But a catch block can’t be there in a program if there is no try block. It is like else-block can only be written if and only if if-block is present in the program.
9. How many catch blocks can a single try block can have?
a) Only 1
b) Only 2
c) Maximum 127
d) As many as required
Answer
Answer: d [Reason:] There is no limit on the number of catch blocks corresponding to a try block. This is because the error can be of any type and for each type, a new catch block can be defined. This is to make sure all type of exceptions can be handled.
10. Which among the following is not a method of Throwable class?
a) public String getMessage()
b) public Throwable getCause()
c) public Char toString()
d) public void printStackTrace()
Answer
Answer: c [Reason:] Actually all the functions are available inthrowable class. But the return type given in the option is wrong. The function toString returns string value. Hence the return type must be a String and not a char.
11. To catch the exceptions ___
a) An object must be created to catch the exception
b) A variable should be created to catch the exception
c) An array should be created to catch all the exceptions
d) A string have to be created to store the exception
Answer
Answer: a [Reason:] The object must be created of a specific class of which the error has occurred. If the type of error is unknown then we can use an object of class Exceptions. This object will be able to handle any kind of exception that a program might produce.
12. Multiple catch blocks ______
a) Are mandatory for each try block
b) Can be combined into a single catch block
c) Are not possible for a try block
d) Can never be associated with a single try block
Answer
Answer: b [Reason:] The separate catch blocks for a single try block can be combined into a single catch block. All type of errors can be then handled in s single block. The type still have to be specified for the errors that might be produced.
13. Which symbol should be used to separate the type of exception handler classes in a single catch block?
a) ?
b) ,
c) –
d) |
Answer
Answer: d [Reason:] A pipe symbol can be used to separate different type of exceptions. The exceptions should always be given in proper sequence to ensure that no code remains unreachable. If not done properly the code might never be used in a program.
14. Which class is used to handle the input and output exceptions?
a) InputOutput
b) InputOutputExceptions
c) IOExceptions
d) ExceptionsIO
Answer
Answer: c [Reason:] There is a specific class to handle each type of exceptions that might be produced in a program. The input and output exceptions can be handled by an object of class IOExcceptions. This class handles all type of input and output exceptions.
15. Why do we use finally block?
a) To execute the block if exception occurred
b) To execute a code when exception is not occurred
c) To execute a code whenever required
d) To execute a code with each and every run of program
Answer
Answer: d [Reason:] Sometimes there is a need to execute a set of code every time the program runs. Even if the exception occurs and even if it doesn’t, there can be some code that must be executed at end of the program. That code is written in finally block. This block is always executed regardless of exceptions occurring.
Object Oriented MCQ Set 5
1. Which among the following best describes the constructors?
a) A function which is called whenever an object is referenced
b) A function which is called whenever an object is created to initialize the members
c) A function which is called whenever an object is assigned to copy the values
d) A function which is called whenever an object is to be given values for members
Answer
Answer: b [Reason:] The constructors are special type of functions which are called whenever an object is created. This is to initialize the data members of the class. The constructor allocates memory space for all the data members.
2. Which among the following best describes destructor?
a) A function which is called just before the objects are destroyed
a) A function which is called after each reference to the object
c) A function which is called after termination of the program
d) A function which is called before calling any member function
Answer
Answer: a [Reason:] The Destructors are special functions which are called just before an object is destroyed. This functions is responsible to free all the allocated resources to the object. Objects are destroyed whenever those go out of scope.
3. Which among the following represents correct constructor?
a) ()classname
b) ~classname()
c) –classname()
d) classname()
Answer
Answer: d [Reason:] The constructors must contain only the class name. The class name is followed by the blank parenthesis or we can have parameters if some values are to be passed.
4. Which among the following is correct syntax for the destructors?
a) classname()
b) ()classname
c) ~classname()
d) -classname()
Answer
Answer: c [Reason:] The destructor must have same name as that of the corresponding class. The class name should be preceded by the tilde symbol (~).
5. Which among the following is true?
a) First the constructor of parent classes are called in sequence of inheritance
b) First the constructor of child classes are called in the sequence of inheritance
c) First constructor called is of the object being created
d) Constructors are called randomly
Answer
Answer: a [Reason:] First the constructor of parent class are called. The order in which the parent class constructors are called is same in the sequence of inheritance used.
6. What is the sequence of destructors call?
a) Same order as that of the constructors call
b) Random order
c) According to the priority
d) Revere of the order of constructor call
Answer
Answer: d [Reason:] The destructors are called in the reverse order as that of the constructors being called. This is done to ensure that all the resources are released in sequence. That is, the derived class destructors will be called first.
7. The destructors _____
a) Can have maximum one argument
b) Can’t have any argument
c) Can have more than one argument
d) Can’t have more than 3 arguments
Answer
Answer: b [Reason:] The destructors doesn’t have any arguments. The destructors have to be called implicitly whenever an object goes out of scope. The user can’t pass argument to the implicit call.
8. Destructor calls ____ (C++)
a) Are only implicit
b) Are only explicit
c) Can be implicit or explicit
d) Are made at end of program only
Answer
Answer: c [Reason:] The destructors are usually called implicitly whenever an object goes out of scope. The destructors can also be called explicitly if required. The call must be made, implicitly or explicitly.
9. Number of destructors called are
a) Always equal to number of constructors called
b) Always less than the number of constructors called
c) Always greater than the number of constructors called
d) Always less than or equal to number of constructors
Answer
Answer: a [Reason:] Destructor will be called only to free the resources allocated for an object. The resources are allocated only the constructor for an object is called.
10. For explicit call _____
a) The destructor must be private
b) The destructor must be public
c) The destructor must be protected
d) The destructor must be defined outside the class
Answer
Answer: b [Reason:] The destructor must be public for explicit calls. If it is made private or protected then it won’t be accessible outside the class. There is no restriction of definition the destructor outside the class.
11. If a class have 4 constructors then it must have 4 destructors also.
a) True
b) False
Answer
Answer: b [Reason:] Even if the class have 4 constructors, only one would be used. And only one destructor is allowed.
12. Which among the following is true for destructors?
a) Destructors can be overloaded
b) Destructors can be define more than one time
c) Destructors can’t be overloaded
d) Destructors are overloaded in derived classes
Answer
Answer: c [Reason:] The destructors can never be overloaded. The destructors doesn’t have arguments. And to get overloaded, they must have different signature. This is not possible if arguments are not allowed.
13. The constructor _______
a) Have a return type
b) May have a return type
c) Of derived classes have return type
d) Doesn’t have a return type
Answer
Answer: d [Reason:] The constructors doesn’t have any return type. The constructors are intended to allocate the resources for the object. Memory spaces are to be finalized.
14. The destructors ______
a) Have a return type
b) May have a return type
c) Of derived classes have return type
d) Doesn’t have a return type
Answer
Answer: d [Reason:] The destructors are intended to free the memory space. And all the resources that were allocated for the object. The return value is not supported since only memory have to be made free.
15. The destructor can be called before the constructor if required. (True/False)
a) True
b) False
Answer
Answer: b [Reason:] The destructors can be called only after the constructor calls. It is not a mandatory rule but the deletion can only take place if there is something created using the constructor.