Pages

oops qun and ans

Q) What is object oriented programming language?
Object-orientation is a set of tools and methods that enable software engineers to build reliable, user friendly, maintainable, well documented, reusable software. System that fulfills the requirements of its users. It is claimed that object-orientation provides software developers with new mind tools to use in solving a wide variety of problems. Object-orientation provides a new view of computation. a software system is seen as a community of objects that cooperate with each other by passing messages in solving a problem.
An object-oriented programming language provides support for the following object-oriented concepts:
·         objects and classes
·         inheritance
·         polymorphism and dynamic binding
Q) What are the Principles of object oriented programming?
 Object orientation is of the programming styles or methodologies. As far as application development is concerned, following are the important object oriented features.
1.    Encapsulation
2.    Inheritance
3.    Polymorphism
Encapsulation:
The concept of binding the data along with its related and corresponding functionalities or functions is known as encapsulation.
The concept of making the data available only to certain related areas or only within mentioned borders is known as binding.
Inheritance:
A key feature of JAVA classes is inheritance. Inheritance allows to create classes which are derived from other classes, so that they automatically include some of its "parent's" members, plus its own.
The concept of getting the properties of one class to another class is known as inheritance.
Polymorphism:
Poly means many and morphism means forms (functionalities), so the concept of defining multiple functionalities or methods with the same name associated with the same object is known as polymorphism.




Q) Give any four advantages of OOPS.
1.    The principle of data hiding helps the programmer to build secure programs
That cannot be invaded by code in other parts of the program.
2.    It is possible to have multiple instances of an object to co-exist without any
Interference
3.    Object oriented programming can be easily upgraded from small to large systems.
4.    Software complexity can be easily managed.

Q) Give any four applications of OOPS
Ø  Real-time systems.
Ø  Simulation and modeling.
Ø  Object-oriented databases.
Ø  AI and expert systems.

Q) What Is Class?
  • Class is nothing but a structure binding the data along with its corresponding and related functions.
  • Class is a user defined data type in java. Class will act as the base for encapsulation.
  • Class is a similar (but not exactly) to “structure” in c programming language to create user defined data types that model real world entities.
  • Class is a not an object oriented feature. But class is the means with which all object oriented features are programmatically realized. For example, encapsulation, polymorphism and inheritance can’t be programmatically achieved without class concept. But it does not mean that class is an object oriented feature.
  • A class contain properties and operations
  • A class is a plan for the proposed object.
  • A class is known as a blueprint or template for an object.
  • Defining a class is nothing but modeling a real world entity. Real world entity type creation is nothing but classification. That is why the name “class” which is nothing but type.
  • Any java application works like collection of classes.
Q) What is general form class definition?
General form of a class definition:
class classname {
type instance-variable1;
type instance-variable2;
// ...
type instance-variableN;
type methodname1(parameter-list) {
// body of method
}
type methodname2(parameter-list) {
// body of method
}
// ...
type methodnameN(parameter-list) {
// body of method
}
}
Q) What is object?
·         Physical realization of a class is nothing but an object.
·         Instantiating a class is nothing but creating an object.
·         A class is the basic of encapsulation. An object implements encapsulation.
·         From class any number of objects of can be created.
·         Object is nothing but some memory area in RAM to store data in a secured manner.
·         Fundamental unit of data storage in an object oriented system to store data in secured manner is nothing but an object.
An object is associated with 3 things:
1.    State
2.    Behavior
3.    Identity
·         Properties/variable/attributes and data stored at that time in those variables put together is nothing but state of the object. I.e. data stored in an object is known as object state.
·         Operations/methods of the object are nothing but object behavior.
·         Name of the object with which it is uniquely identified is nothing but identify of an object.




Q) What is the need of object?

Ans: In order to allocate memory space and load the members of a class to the RAM from the byte code at the Run time we need object.
Q) Explain Creating Objects in Java?
-> We know that a class is a collection of variables and the methods that access those variables. Generally, when a program starts execution, the JVM first loads the main() method into memory and starts execution. Because the main() is residing in memory, the remaining members of the class are not available to main(). To make the remaining members of a class(non-static) available to main(), we create objects. That is ,an Object is the memory created for the members (non-static) of a class. The procedure for creating an object is as follows:
       Obtaining objects of a class is a two-step process.
       First, declare a variable of the class type. This variable does not define an object. Instead, it is simply a variable that can refer to an object.
class-name reference;
       Second, acquire an actual, physical copy of the object and assign it to that variable using the new operator.
reference = new class-name();
       The new operator dynamically allocates (that is, allocates at run time) memory for an object and returns a reference to it.
       This reference is, more or less, the address in memory of the object allocated by new.
       This reference is then stored in the variable. Thus, in Java, all class objects must be dynamically allocated.
       At this point, you might be wondering why you do not need to use new for such things as integers or characters.
       The answer is that Java’s simple types are not implemented as objects.
       Rather, they are implemented as “normal” variables. This is done in the interest of efficiency.
       It is important to understand that new allocates memory for an object during run time.
        The advantage of this approach is that your program can create as many or as few objects as it needs during the execution of your program.
For example, for a class Sample, we can create an object as follows :
Sample s;
s = new Sample();
->We can also create an object in a single statement as follows:
                         class-name reference = new class-name();
Eg : Sample s = new Sample();
-> Once the object is created, we can access the class members in main() using the dot(.) operator.
Q) What object contains?
Ans: Object of any class contains only data. Object of a class would not contain the logics or the functionalities of a function.
Q) If you modify one object data will another object data also be modified?
No, modifications done for one object will not be affected to another object.
Q) Till what period of time object of a class would be persistent?
Ans: As long as address of the object is persistent, the object is also persistent in the ram. Once address of the object is loss, Automatically the corresponding object deleted from the ram.
Q) When object is available to a method?
Ans: whenever we make a method call with an object and if the functionality of a method is loaded to the ram because of an object, then we can says that object is available for that method.
All the non-static members of a class would be directly available to every non–static method of the same class.
Q) What are the instance variable?
Ans: Any non static variable of a class can be called as an instance variable. All the non static variables of a class would be loaded to the ram through an instance of class. And there all present inside of a class thus these variables are known as instance variable.

Q) What is the difference between a reference variable and pointer variable in java?
Ans: A pointer variable contains the actual address but where as a reference variable contains only the index of the address.
The actual address of an object would be maintained by the jvm internally and that can be seen by the end user. Thus people say that java doesn’t support pointers. But java support pointers, that pointer are called as restricted pointers. Restricted pointers mean pointers without arithmetic support.  


Q) What is dynamic Binding?
Linking the statements of a method when it is called, is called “Binding”. If the statements of a method are linked at the time of program compilation, it is called “Static Binding” (E.g.: C-Language). If the statements of a method are linked at the time of program execution, it is called “Dynamic Binding” (E.g.: OO languages).
Q) What is message passing?
Objects communicate with each other by passing messages between them which we call message passing. Message Passing involves:
  1. creating classes
  2. creating object
  3. establishing link with objects
 E.g.:  b. deposit (SB2045,20000);
Q) What is Data Abstraction?
The major goal of OOP is “Data Security”. This can be achieved by hiding variables of a class from external functions. This concept of hiding the data members of a class from outside functions is called “Data Abstraction”.
Q) What are different types of inner classes?
A) Nested top-level classes- If you declare a class within a class and specify the static modifier, the compiler treats the class just like any other top-level class. Any class outside the declaring class accesses the nested class with the declaring class name acting similarly to a package. e.g., outer. Inner. Top-level inner classes implicitly have access only to static variables. There can also be inner interfaces. All of these are of the nested top-level variety.

Member classes - Member inner classes are just like other member methods and member variables and access to the member class is restricted, just like methods and variables. This means public member class acts similarly to a nested top-level class. The primary difference between member classes and nested top-level classes is that member classes have access to the specific instance of the enclosing class.

Local classes - Local classes are like local variables, specific to a block of code. Their visibility is only within the block of their declaration. In order for the class to be useful beyond the declaration block, it would need to implement a more publicly available interface. Because local classes are not members the modifiers public, protected, private and static are not usable.

Anonymous classes - Anonymous inner classes extend local inner classes one level further. As anonymous classes have no name, you cannot provide a constructor.
Inner class inside method cannot have static members or blocks
Q) How to declare classes, methods and attributes in java?
Declaring Classes:
 <Access_Specifier> class <Class_name> {
                   <attribute declaration>;
                   <constructor declaration>;
                   <Method declaration>
          }

Declaring Attributes:
         
          <Access_Specifier> <type> <name>=<initial-value>;
Declaring Methods:
          <Access_Specifier> <return_type> <name>( <argument>){
                   <statements>
          }
 Q) What is the difference between procedural and object-oriented programs?
1. In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOP program, unit of program is object, which is nothing but combination of data and code.
2. In procedural program, data is exposed to the whole program whereas in OOPs program, it is accessible within the object and which in turn assures the security of the code.
Q) Differentiate between the message and method.
Message
* Objects communicate by sending messages to each other.
* A message is sent to invoke a method.
Method
* Provides response to a message
* It is an implementation of an operation
.
Q) How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns..
Q) Is size of a keyword?
The size of operator is not a keyword..

Q) Does garbage collection guarantee that a program will not run out of memory?
Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection.