Thursday 14 March 2013

Frequently asked Object-Oriented Programming (OOP) questions.

Q.1 What is multithreading?
Multithreading is the technique in which more than one thread run independent of each other within the process.

Q.2 Does a class inherit the constructors of its superclass?
No, a class does not inherit constructors from any of its super classes.

Q.3 Class declared without any access modifiers, where may the class be accessed?
The class can only be accessed by other classes and interfaces that are defined within the same package.

Q.4 What is difference between overloading and overriding?
In overloading, there is a relationship between methods available in the same class whereas while in  overriding, there is relationship between a superclass method and subclass method.

Q.5 What is a dangling pointer?
A dangling pointer arises when you use the address of an object after its lifetime is over. 

Q.6 Differentiate Abstract Class and Interface?
Abstract Class allows the other classes to inherit from it but cannot be instantiated. 
Interface has only the declaration of the methods without the body.

Q.7 What is the difference between const and static?
Static keyword defines the scope of variables whereas const keyword defines the value of variable that can't be changed during program execution.

Q.8 What is static method in java?
A static method is one that belongs to a class rather than an object of a class. It can be invoked with class name while Non-static method belongs to an object of a class and can be invoked by the object of that class.

Q.9 What is polymorphism? Briefly explain with at least one example.
Polymorphism allows a function, or an object to have more than one forms. e.g. overloading.

Q.10 Differentiate multiple inheritance and multilevel inheritance?
In multiple inheritance a class can be derived from multiple classes while in multilevel inheritance a class can be derived from only one base class and this derived class become the base class of other class.

Q.11 What is early (compile-time) and late (run-time) binding?
In early (compile-time) binding the assignment of values to variables occur during the design time.
In late (run-time) binding the assignment of values to variables occur at run-time.

Q.12 What is exception handling?
An exception is basically an event that can occur during the execution of a program. These exceptions are handled properly through exception handling i.e. throw, try and catch keywords.

Q.13 What is “super” keyword?
Super keyword is used to invoke overridden method of the super class in derived class.

Q.14 What is inline function?
Compiler inserts/copy complete body of the function wherever that function is used/called in the program.

Q.15 How multiple inheritance implemented in java?

In fact multiple inheritance is not allowed in java. Java interfaces can be implemented instead of multiple inheritance.

No comments:

Post a Comment