Sie sind auf Seite 1von 5

1- What is the difference between procedural and object-oriented programs?

a) 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. b) In procedural program, data is exposed to the whole program whereas in OOPs program, it is accessible with in the object and which in turn assures the security of the code. 2- What are Encapsulation, Inheritance and Polymorphism? - Encapsulation is the mechanism that binds together code and data it manipulates and eeps both safe from outside interference and misuse. Inheritance is the process by which one object ac!uires the properties of another object. Polymorphism is the feature that allows one interface to be used for general class actions. - What is the difference between !ssignment and Initiali"ation? - "ssignment can be done as many times as desired whereas initiali#ation can be done only once. #- What is $$Ps? - Object oriented programming organi#es a program around its data, i. e. , objects and a set of well defined interfaces to that data. "n object-oriented program can be characteri#ed as data controlling access to code. %- What are &lass, &onstructor and Primiti'e data types? - $lass is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. $onstructor is a special ind of

method that determines how an object is initiali#ed when created. Primiti%e data types are & types and they are' byte, short, int, long, float, double, boolean, char. (- What is an $bject and how do you allocate memory to it? - Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. (hen an object is created using new operator, memory is allocated to it. )- What is the difference between constructor and method? - $onstructor will be automatically in%o ed when an object is created whereas method has to be called explicitly. *- What are methods and how are they defined? - )ethods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes. )ethod definition has four parts. *hey are name of the method, type of object or primiti%e type the method returns, a list of parameters and the body of the method. " method+s signature is a combination of the first three parts mentioned abo%e. +- What is the use of bin and lib in ,-.? - ,in contains all tools such as ja%ac, applet%iewer, awt tool, etc., whereas lib contains "PI and all pac ages. 1/- What is casting? - $asting is used to con%ert the %alue of one type to another. 11- 0ow many ways can an argument be passed to a subroutine and e1plain them?

- "n argument can be passed in two ways. *hey are passing by %alue and passing by reference. Passing by %alue' *his method copies the %alue of an argument into the formal parameter of the subroutine. Passing by reference' In this method, a reference to an argument -not the %alue of the argument) is passed to the parameter. 12- What is the difference between an argument and a parameter? - (hile defining method, %ariables passed in the method are called parameters. (hile using those methods, %alues passed to those %ariables are called arguments. 1 - What are different types of access modifiers? - public' "ny thing declared as public can be accessed from anywhere. pri%ate' "ny thing declared as pri%ate can+t be seen outside of its class. protected' "ny thing declared as protected can be accessed by classes in the same pac age and subclasses in the other pac ages. default modifier ' $an be accessed only to classes in the same pac age. 1#- What is final, finali"e23 and finally? - final ' final eyword can be used for class, method and %ariables. " final class cannot be subclassed and it pre%ents other programmers from subclassing a secure class to in%o e insecure methods. " final method can+t be o%erridden. " final %ariable can+t change from its initiali#ed %alue. finali#e-) ' finali#e-) method is used just before an object is destroyed and can be called just prior to garbage collection. finally ' finally, a ey word used in exception handling, creates a bloc of code that will be executed after a try.catch bloc has completed and before the code following the try.catch bloc . *he finally bloc will execute whether or not an exception is thrown. /or example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exceptionhandling mechanism. *his finally eyword is designed to address this contingency.

1%- What is 45I&$-E? - 0nicode is used for internal representation of characters and strings and it uses 12 bits to represent each other. 1(- What is 6arbage &ollection and how to call it e1plicitly? - (hen an object is no longer referred to by any %ariable, ja%a automatically reclaims memory used by that object. *his is nown as garbage collection. 3ystem. gc-) method may be used to call it explicitly. 1)- What is finali"e23 method? - finali#e -) method is used just before an object is destroyed and can be called just prior to garbage collection. 1*- What are 7ransient and 8olatile 9odifiers? - *ransient' *he transient modifier applies to %ariables only and it is not stored as part of its object+s Persistent state. *ransient %ariables are not seriali#ed. 4olatile' 4olatile modifier applies to %ariables only and it tells the compiler that the %ariable modified by %olatile can be changed unexpectedly by other parts of the program. 1+- What is method o'erloading and method o'erriding? - )ethod o%erloading' (hen a method in a class ha%ing the same method name with different arguments is said to be method o%erloading. )ethod o%erriding ' (hen a method in a class ha%ing the same method name with same arguments is said to be method o%erriding. 2/- What is difference between o'erloading and o'erriding? - a) In o%erloading, there is a relationship between methods a%ailable in the same class whereas in o%erriding, there is relationship between a superclass method and subclass

method. b) O%erloading does not bloc inheritance from the superclass whereas o%erriding bloc s inheritance from the superclass. c) In o%erloading, separate methods share the same name whereas in o%erriding, subclass method replaces the superclass. d) O%erloading must ha%e different method signatures whereas o%erriding must ha%e same signature. 21- What is meant by Inheritance and what are its ad'antages? - Inheritance is the process of inheriting all the features from a class. *he ad%antages of inheritance are reusability of code and accessibility of %ariables and methods of the super class by subclasses. 22- What is the difference between this23 and super23? - this-) can be used to in%o e a constructor of the same class whereas super-) can be used to in%o e a super class constructor. 2 - What is the difference between superclass and subclass? - " super class is a class that is inherited whereas sub class is a class that does the inheriting. 2#- What modifiers may be used with top-le'el class? - public, abstract and final can be used for top-le%el class. 2%- What are inner class and anonymous class? - Inner class ' classes defined in other classes, including those defined in methods are called inner classes. "n inner class can ha%e any accessibility including pri%ate. "nonymous class ' "nonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot ha%e explicit constructors.