Basics of Object Oriented Programming

Q.1  What is OOP(Object Oriented Programming)?

Ans : OOPs (Object Oriented Programs) is object based programming language. It uses object for accessing and manipulating data. It supports reusability of code.

Q.2  What is Procedure Oriented Programming?

Ans : Procedure Oriented Programming is based on procedure (also know as function or method). In procedure oriented programming, programs are divided into different modules.

 

Q.3  What is a Class?

Ans : A class can be define as a blueprint or template  for  multiple objects having similar features and properties. A class defines the operations that an object can perform and the data that it can hold.

 

Q.4  What is Abstraction?

Ans : Abstraction can be define as focusing on only relevant properties and hiding the complex implementation of a program.

 

Q.5  What is difference between Object Oriented and Procedure Oriented programming?

Ans: In procedure oriented, data can be accessed in whole program directly. In object oriented, data can not be accessed directly, an object is used to access data.
  • In procedure oriented, data is not secure. In object oriented, data is secure as it can only be accessed through object.
  • In procedure oriented, program is divided into different procedures. In object oriented, program is divided into classes and object of class is used to access class members (methods and variables).

 

Q.6  Is JAVA a completely Object Oriented Programming Language?

Ans:  The answer to this question is certainly no. The reason behind this is JAVA does not obey the OOPs concept purely. Certain concepts like Operator over loading and Multiple Inheritance are not supported by JAVA. Hence JAVA is known as Partially Object Oriented Programming Language.

 

Q.7  What is Encapsulation?

Ans : Encapsulation can be define as mechanism to bind data and code together.  It keep both data and code secure from outside interfaces and misuse.

 

Q.8  What is an Object ?

Ans:  It is a basic unit of a system. An object is an entity that has attributes, behavior, and identity. Objects are members of a class. Attributes and behavior of an object are defined by the class definition.

 

Q.9  What is Inheritance?

Ans : Inheritance can be define as the process in which one object acquire properties of another object.

 

Q.10  What is the relation between Classes and Objects?

Ans:  They look very much same but are not same. Class is a definition, while object is instance of the class created. Class is a blue print while objects are actual objects existing in real world. Example we have class CAR which has attributes and methods like Speed, Brakes, Type of Car etc.Class CAR is just a prototype, now we can create real time objects which can be used to provide functionality. Example we can create a Maruti car object with 100 km speed and urgent brakes.

 

Q.11  What are main features of OOPs?

Ans: 
        Abstraction
        Encapsulation
        Inheritance
        Polymorphism

 

Q.12  What is Polymorphism?

Ans : Polymorphism can be define as creating different forms of a method or object for different uses.

 

Q.13  What is the difference between Abstract classes and Interfaces ?

Ans:  Difference between Abstract class and Interface is as follows:-
Abstract class can only be inherited while interfaces can not be it has to be implemented.
Interface cannot implement any methods, whereas an abstract class can have implementation.
Class can implement many interfaces but can have only one super class.
Interface is not part of the class hierarchy while Abstract class comes in through inheritance.
Unrelated classes can implement the same interface.
       


Q.14  What is difference between Static and Non-Static fields of a class ?

Ans:  Non-Static values are also called as instance variables. Each object of the class has its own copy of Non-Static instance variables. So when a new object is created of the same class it will have completely its own copy of instance variables. While Static values have only one copy of instance variables and will be shared among all the objects of the class.
       

Q.15  What is a constructor in class?

Ans:  Constructor has the same name as the class in which it resides and looks from syntax point of view it looks similiar to a method. Constructor is automatically called immediately after the object is created, before the new operator completes. Constructors have no return type, not even void. This is because the implicit return type of a class' constructor is the class type itself. It is the constructor's job to initialize the internal state of an object so that the code creating an instance will have a fully initialized, usable object immediately.
       

Q.16  Can constructors be parameterized?

Ans:  Yes we can have parameterized constructor which can also be termed as constructor overloading.
       

Q.17  What is the use if instanceof keyword? and How do refer to a current instance of object?

Ans:  "instanceof" keyword is used to check what is the type of object.we can refer the current instance of object using "this" keyword. For instance if we have class which has color property we can refer the current object instance inside any of the method using "this.color".
       

Q.18  What are access modifiers?

Ans:  Access modifiers decide whether a method or a data variable can be accessed by another method in another class or subclass.
four types of access modifiers:
  • Public: - Can be accessed by any other class anywhere.
  • Protected: - Can be accessed by classes inside the package or by subclasses ( that means classes who inherit from this class).
  • Private - Can be accessed only within the class. Even methods in subclasses in the same package do not have access.
  • Default - (Its private access by default) accessible to classes in the same package but not by classes in other packages, even if these are subclasses.

Q.19  Define exceptions ?

Ans:  An exception is an abnormal condition that arises in a code sequence at run time. Basically there are four important keywords which form the main pillars of exception handling: try, catch, throw and finally. Code which you want to monitor for exception is contained in the try block. If any exception occurs in the try block its sent to the catch block which can handle this error in a more rational manner. To throw an exception manually you need to call use the throw keyword. If you want to put any clean up code use the finally block. The finally block is executed irrespective if there is an error or not.
       
Q.20  Why JAVA is known as securable language?

Ans:  There are two reasons behind this. The first one is, as JAVA runs in JVM, which is a virtual machine, and it converts source code to byte code, which is not understandable for humans, so its safe. The second reason is JAVA does not support the Pointer concept, hence we can say that JAVA is a securable language.

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Hostgator Coupon Code