Tuesday 31 May 2022

Question. Paper-PGDCA/MSCCS-03/MCa-103/CPCJ | Oops Programming with C++ and Java

 

(i) in C++, the predefined object cout is an instance of which class?

Sol:- The predefined object cout is an instance of ostream class.

 

(ii) Which operator is used to allocate memory dynamically in c++?

Sol: - New

Remember

C++ supports dynamic allocation and deallocation of objects using the new and delete operators. These operators allocate memory for objects from a pool called the free store (also known as the heap).

 

(iii) if the return type of a function in c++ is void, what will it return?

Sol:- do not return anything

 

(iv) if we check the size of an integer variable on different plateforms/operating systems, will it return same value in c++?

Sol: No, If 16 bit OS sizeof(int) = 2 byte, for 32 bit sizeof(int) = 4 byte, for 64 bit sizeof(int)=8 byte

 

(v) Why syntax do you use in order to inherit a class from another class in c++?

Sol:-

Syntex

class  <derived_class_name> : <access-specifier> <base_class_name>

{

        //body

}

 

Where

class      — keyword to create a new class

derived_class_name   — name of the new class, which will inherit the base class

access-specifier  — either of private, public or protected. Is neither is specified, PRIVATE is taken as default

base-class-name  — name of the base class

(vi) What does init () Method do in applets in Java?

Sol:  init () method is used to initialize an applet. It is invoking only once at the time of initialization. Initialized objects are created by the web browser.

 

(Vii) Write the output of Following piece of code in java

for(int i=0; i<10; i++)

{

                if(i==4)

                {

                                break;

                }

                System.out.println(i);

}

 

Output:-

0123

 

(viii) What is the purpose of using finally statement in java?

Sol:  

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.

 

कभी-कभी प्रोग्राम के चलने पर हर बार हमें कोड के एक सेट को निष्पादित करने की आवश्यकता होती है। हमें अपवाद हो या नहीं हमें कुछ कोड को प्रोग्राम के अंत में निष्पादित किया जाना आवश्‍यक होता है। वह कोड अंत में फाइनली ब्लॉक में लिखा गया है। अपवादों की परवाह किए बिना इस ब्लॉक को हमेशा निष्पादित किया जाता है।

No comments:

Post a Comment