Vous êtes sur la page 1sur 4

OOPS

Important two marks:


1. What is the advantage of an inline function?
An inline function is one in which the function code replaces the function call
directly. Inline functions are those whose function body is inserted in place of the
function call statement during the compilation process
Advantage:
Execution time of the function is less than the time required to establish linkage
between the calling and called function.
Flexibility and modularity of function
Achieve computational speedup.

2. Illustrate the usage of this pointer in C++.


C++ has access to its own address through an important pointer called this
pointer. Using the keyword this we can access the data member in the object.
this pointer is an implicit parameter to all member functions. Therefore, inside a
member function, this may be used to refer to the invoking object.
Friend functions do not have this pointer, because friends are not members of a
class. Only member functions have this pointer.
This pointer cannot access static data member functions.

3. What is a destructor? Illustrate with an example.


When an object is no longer needed it can be destroyed.
A class can have another special member function called destructor, which is
called when the object is destroyed.
Destructor is a member function having the character ~(tilde) followed by the
name of its class and brackets.
It should be declared as follows,
~classname( );
The destructor can be called automatically when the object goes out of scope and
is no longer needed.
General format
classclassname
{
// private members
public:
~classname( ); // destructor prototype or declaration
};
class name :: ~ classname( )
{
// destructor body definition

1
}

4. What is a pure virtual function?


A virtual function, equated to zero is called a pure virtual function.
It is function declared in a base class that has no definition relative to the base
class .
A class containing such pure function is called an abstract class.
Syntax,
virtual void display()=0;

5. What is generic programming?


Generic programming means that you are not writing source code that is
compiled as-is but that you write "templates" of source codes that the compiler in the
process of compilation transforms into source codes.
The simplest example for generic programming is container classes like arrays,
lists or maps that contain a collection of other objects.

6. What is a template?
Templates are the foundation of generic programming, which involves writing
code in a way that is independent of any particular type.
A template is a blueprint or formula for creating a generic class or a function. The
library containers like iterators and algorithms are examples of generic
programming and have been developed using template concept.
There is a single definition of each container, such as vector, but we can define
many different kinds of vectors for example, vector <int> or vector <string>.

7. Define the keyword static in java.


The static keyword in Java means that the variable or function is shared between
all instances of that class as it belongs to the type, not the actual objects themselves.
So if you have a variable: private static int i = 0; and you increment it ( i++ ) in
one instance, the change will be reflected in all instances.

8. Write the output produced by the following Code Fragments.


System.out.println(Result+40+30);
System.out.println(Result+(40+30));
OUTPUT:
Result 40 30
Result 70

9. Distinguish between interface and class in java.


A class is nothing but a blueprint or a template for creating different objects
whichdefines its properties and behaviors. Java class objects exhibit the properties and

2
behaviors defined by its class. A class can contain fields and methods to describe the
behavior of an object.
An interface is a reference type in Java. It is similar to class. It is a collection of
abstract methods. A class implements an interface, thereby inheriting the abstract
methods of the interface. Along with abstract methods, an interface may also contain
constants, default methods, static methods, and nested types.

10. What is multithreading?


Multithreading is a conceptual programming paradigm where a program (process)
is divided into two or more subprograms which can be implemented at the same time in
parallel.
A single Java program can have many different threads executing independently
and continuously. Multiple Java applets can run on the browser at the same time sharing
the CPU time.

11. Define Static Member Functions?


Static Function can have accessed by only static members declared in the same
class. Static member function called using the name of class instead of its objects.

12. Define Friend Function.


Private members cannot be accessed from outside the class. To make an outside function
Friendly to a class, declare this function as a friend of the class.

13. What are the benefits of inheritance?


Code Reuse
Ease of code maintainence
Increase reliability
Improved performance
Less maintenance
Easy to extension

14. What is meant by bytecode in java?


Java compiler after compiling the program creates a new file referred as the class
file, which contains a special code referred as the bytecode. It is similar to machine
language, but unlike machine language, java byte code is exactly the same on every
platform.

15. Define Garbage Collection in Java?


Garbage Collection also referred as automatic memory management. Periodically
frees the memory used by objects that are no longer needed. The garbage collector in java
scans dynamic memory areas for objects and marks those that are referenced. After all
possible paths to objects are investigated the unreferenced objects are freed.

3
16. What are the life cycles of thread?
New born state
Runnable state
Running state
Blocked state
Dead state

Vous aimerez peut-être aussi