MSCCS-103 (Assignment : July-2023, Jan-2024)

Internal Assignment for July-2023 and January-2024. Paper Code (MSCCS-103) (OOPS Programming with C++ and JAVA).

Section-A

Q.A.1 : What does “this” pointer point to ? Give an example.

Ans (Q.A.1) : The this pointer is a pointer accessible only within the nonstatic member functions of a classstruct, or union type. It points to the object for which the member function is called. Static member functions don’t have a this pointer.

Syntax : 
this
this->member-identifier
Examples : (In C++)
void Date::setMonth( int mn )
{
   month = mn;            // These three statements
   this->month = mn;      // are equivalent
   (*this).month = mn;
}

Q.A.2 : What is difference between subclass and super class? Give an example.

Ans (Q.A.2) : Definitions: A class that is derived from another class is called a subclass (also a derived classextended class, or child class). The class from which the subclass is derived is called a superclass (also a base class or a parent class).

Syntax : 
class  <derived_class_name> : <access-specifier> <base_class_name>
{
        //body
}
Example: There are four examples below- (Where ABC is Sub-Class and XYZ is Super-class. And Private/Public/Protected are access-specifier.)

1. class ABC : private XYZ              //private derivation
            {                }
2. class ABC : public XYZ              //public derivation
            {               }
3. class ABC : protected XYZ              //protected derivation
            {              }
4. class ABC: XYZ                            //private derivation by default
{            }

Q.A.3 : Give difference between Thread and Process ?

Ans (Q.A.3) : There are some basic differences between Thread and Process-

S. No. Process Thread
1When a program is under execution, then it is known as a process.A segment of a process is known as thread.
2Processes are independent of each other and hence don’t share a memory or other resources.Threads are interdependent and share memory.
3Each process is treated as a new process by the operating system.The operating system takes all the user-level threads as a single process.
4If one process gets blocked by the operating system, then the other process can continue the execution.If any user-level thread gets blocked, all of its peer threads also get blocked because OS takes all of them as a single process.
5The data segment and code segment of each process are independent of the other.Threads share data segment and code segment with their peer threads; hence are the same for other threads also.
6It is a heavy weight process. So, It takes more resources.It is a light weight process. So, It takes less resources.
7Multiprogramming holds the concepts of multi-process.We don’t need multi programs in action for multiple threads because a single process consists of multiple threads.
8A system call is involved in it.No system call is involved, it is created using APIs.
Table of Difference between Thread and Process.

Q.A.4 : List some properties of the constructor function in C++ ?

Ans (Q.A.4) : There are some main Characteristics of Constructor function in C++

  • The name of the constructor is the same as its class name.
  •  It constructs the values i.e. provides data for the object which is why it is known as a constructor.
  • Constructors are mostly declared in the public section of the class though they can be declared in the private section of the class.
  • A constructor gets called automatically when we create the object of the class.
  • Constructors do not return values; hence they do not have a return type.
  • Constructors can be overloaded.
  • A constructor can not be declared virtual.
  • A constructor cannot be inherited.
  • The addresses of the Constructor cannot be referred to.
  • The constructor makes implicit calls to new and delete operators during memory allocation.

Section-B

Q.B.1 : Explain the various data types of java that are not in C++ ? Justify its importance.

Ans (Q.B.1) : Coming Soon….. Keep Visiting.

Q.B.2 : What is Constructor ? Explain its role.

Ans (Q.B.2) : A constructor is a special method of a class or structure in object-oriented programming that initializes a newly created object of that type. Whenever an object is created, the constructor is called automatically.

The purpose of a constructor is to construct an object and assign values to the object’s members. A constructor takes the same name as the class to which it belongs, and does not return any values.

The following are some main characteristics of the constructors –

  • The name of the constructor is the same as its class name.
  • Constructors are mostly declared in the public section of the class though they can be declared in the private section of the class.
  • Constructors do not return values; hence they do not have a return type.
  • Constructors can be overloaded.
  • A constructor can not be declared virtual.
  • A constructor cannot be inherited.
  • The addresses of the Constructor cannot be referred to.
  • The constructor makes implicit calls to new and delete operators during memory allocation.
Types of Constructor :

Constructors can be classified based on in which situations they are being used.

  • Default Constructor
  • Parameterized Constructor
  • Copy Constructor
  • Move Constructor

Q.B.3 : Define various types of loops with suitable examples ?

Ans (Q.B.3) : Coming soon…..keep visiting.

Q.B.4 : What is the difference between “Overloading” and “Overriding” in Java ?

Ans (Q.B.4) : Programming involves many ideas like polymorphism, inheritance, data abstraction, and handling exceptions.  Ideas like method overloading and method overriding are part of Polymorphism.

Definition: Method overloading refers to defining multiple methods with the same name but different parameters within the same class, while Method overriding involves creating a method in the child class that has the same name, parameters, and return type as a method in the parent class.

The differences between Method Overloading and Method Overriding are as follows:-

S. No.Method OverloadingMethod Overriding
1Method overloading is a compile-time polymorphism.Method overriding is a run-time polymorphism.
2Method overloading helps to increase the readability of the program.Method overriding is used to grant the specific implementation of the method which is already provided by its parent class or superclass.
3It occurs within the class.It is performed in two classes with inheritance relationships.
4Method overloading may or may not require inheritance.Method overriding always needs inheritance.
5In method overloading, methods must have the same name and different signatures.In method overriding, methods must have the same name and same signature.
6In method overloading, the return type can or can not be the same, but we just have to change the parameter.In method overriding, the return type must be the same or co-variant.
7Static binding is being used for overloaded methods.Dynamic binding is being used for overriding methods.
8Poor Performance due to compile time polymorphism.It gives better performance. The reason behind this is that the binding of overridden methods is being done at runtime.
9Private and final methods can be overloaded.Private and final methods can’t be overridden.
10The argument list should be different while doing method overloading.The argument list should be the same in method overriding.
Differences between Method Overloading and Method Overriding

Section-C

Q.C.1 : Distinguish between Exception and Error with suitable example ? Also describe hierarchy of subclasses of exception related classes ?

Ans (Q.C.1) : Coming soon…..keep visiting.

Q.C.2 : What does Polymorphism mean in C++ Language ? How is polymorphism achieved at (a) compile time, (b) Run time.

Ans (Q.C.2) : For Answer Click Here.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *