cs2305- pp 2 marks

24
CS2305- PROGRAMMING PARADIGMS 2-MARK Questions and Answers UNIT I OBJECT-ORIENTED PROGRAMMING – FUNDAMENTALS 1) What is meant by Object Oriented Programming? OOP is a method of programming in which programs are organised as cooperative collections of objects. Each object is an instance of a class and each class belong to a hierarchy. 2) What is a Class? Class is a template for a set of objects that share a common structure and a common behaviour. 3) What is an Object? Object is an instance of a class. It has state,behaviour and identity. It is also called as an instance of a class. 4) What is an Instance? An instance has state, behaviour and identity. The structure and behaviour of similar classes are defined in their common class. An instance is also called as an object. 5) What are the core OOP’s concepts? Abstraction, Encapsulation,Inheritance and Polymorphism are the core OOP’s concepts. 6) What is meant by abstraction? Abstraction defines the essential characteristics of an object that distinguish it from all other kinds of objects. Abstraction provides crisply-defined conceptual boundaries relative to the perspective of the viewer. Its the process of focussing on the essential characteristics of an object. Abstraction is one of the fundamental elements of the object model.

Upload: arivazhagan-chinnamadhu

Post on 17-Aug-2015

215 views

Category:

Documents


1 download

DESCRIPTION

PP 2 marks

TRANSCRIPT

CS2305- PROGRAMMING PARADIGMS2-MARK Questions and AnswersUNI I O!"#C-ORI#N#D PROGRAMMING $ %UNDAM#NA&S1) What is meant by Object Oriented Programming? OOP is a method of programming in which programs are organised as cooperative collections of objects. Each object is an instance of a class and each class belong to a hierarchy.2) What is a lass? lass is a template for a set of objects that share a common str!ct!re and a common behavio!r.") What is an Object? Object is an instance of a class. #t has state$behavio!r and identity. #t isalso called as an instance of a class.%) What is an #nstance? &n instance has state$ behavio!r and identity. 'he str!ct!re and behavio!r of similar classes are defined in their common class. &n instance is also called as an object.() What are the core OOP)s concepts? &bstraction$ Encaps!lation$#nheritance and Polymorphism are the core OOP)s concepts.*) What is meant by abstraction? &bstraction defines the essential characteristics of an object that disting!ish it from all other +inds of objects. &bstraction provides crisply,defined concept!al bo!ndaries relative to the perspective of the viewer. #tsthe process of foc!ssing on the essential characteristics of an object. &bstraction is one of the f!ndamental elements of the object model.-) What is meant by Encaps!lation? Encaps!lation is the process of compartmentalising the elements of an abtraction that defines the str!ct!re and behavio!r. Encaps!lation helps toseparate the contract!al interface of an abstraction and implementation..) What are Encaps!lation$ #nheritance and Polymorphism? Encaps!lation is the mechanism that binds together code and data it manip!lates and +eeps both safe from o!tside interference andmis!se. #nheritance is the process by which one object ac/!ires the properties of another object. Polymorphism is the feat!re that allows one interface to be !sed for general class actions. 0) What are methods and how are they defined? 1ethods are f!nctions that operate on instances of classes in which they are defined. Objects can comm!nicate with each other !singmethods and can call methods in other classes. 1ethod definition has fo!rparts. 'hey are name of the method$ type of object or primitive type the method ret!rns$ a list of parameters and the body of the method. & method)s signat!re is a combination of the first three parts mentioned above. 12) What are different types of access modifiers 3&ccess specifiers)?&ccess specifiers are +eywords that determine the type of access to the member of a class. 'hese +eywords are for allowingprivileges to parts of a program s!ch as f!nctions and variables. 'hese are4 public' &ny thing declared as p!blic can be accessed from anywhere. private' &ny thing declared as private can)t be seen o!tside of its class. protected' &ny thing declared as protected can be accessed by classes in the same pac+age and s!bclasses in the other pac+ages. default modifier ' an be accessed only to classes in the same pac+age.11) What is an Object and how do yo! allocate memory to it? Objectis an instance of a class and it is a software !nit that combines a str!ct!red set ofdata with a set of operations for inspecting and manip!lating that data. When an object is created !sing new operator$ memory is allocated to it. 12) E5plain the !sage of 6ava pac+ages. 'his is a way to organi7e files when a project consists of m!ltiple mod!les. #t also helps resolve naming conflicts when different pac+ages have classes with the same names. Pac+ages access level also allows yo! to protect data from being !sed by the non,a!thori7ed classes. 1") What is method overloading and method overriding?1ethod overloading4 When a method in a class having the same method name with different arg!ments is said to be method overloading. 1ethod overriding 4 When a method in a class having the same method name with same arg!ments is said to be method overriding.14) What gives java it)s 8write once and r!n anywhere9 nat!re?&ll 6ava programs are compiled into class files that contain bytecodes. 'hese byte codes can be r!n in any platform and hence java is said to be platform independent.1() What is a constr!ctor? What is a destr!ctor? onstr!ctor is an operation that creates an object and:or initialises its state. ;estr!ctor is an operation that frees the state of an object and:or destroys the object itself. #n 6ava$ there is no concept of destr!ctors. #ts ta+en care by the 6arbage ollection and how to call it e5plicitly? When an object is no longer referred to by any variable$ javaa!tomatically reclaims memory !sed by that object. 'his is +nown as garbage collection. ?ystem. gc3) method may be !sed to call it e5plicitly10) #n 6ava$ @ow to ma+e an object completely encaps!lated? &ll the instance variables sho!ld be declared as private and p!blic getter and setter methods sho!ld be provided for accessing the instance variables.22) What is static variable and static method? static variable is a class variable which val!e remains constant for the entire classstatic method is the one which can be called with the class itself and can hold only the staic variables21) What is finali7e3) method?finali7e 3) method is !sed j!st before an object is destroyed and canbe called j!st prior to garbage collection.22) What is the difference between ?tring and ?tring A!ffer? a) ?tring objects are constants and imm!table whereas ?tringA!ffer objects are not. b) ?tring class s!pports constant strings whereas ?tringA!ffer class s!pports growable and modifiable strings. 2") What is the difference between &rray and vector? &rray is a set of related data type and static whereas vector is a growable array of objects and dynamic2%) What is a pac+age? & pac+age is a collection of classes and interfaces that provides a high,level layer of access protection and name space management.2() What is the difference between this3) and s!per3)? this3) can be !sed to invo+e a constr!ctor of the same class whereas s!per3) can be !sed to invo+e a s!per class constr!ctor. 2*) E5plain wor+ing of 6ava raphics object. 'he repaint3)method is !sed to ca!se paint3) to be invo+ed by the &W' painting thread.() Which containers !se a border =ayo!t as their defa!lt layo!t?'he window$ Drame and ;ialog classes !se a border layo!t as their defa!lt layo!t.*) What is the difference between applications and applets? a)&pplication m!st be r!n on local machine whereas applet needs no e5plicit installation on local machine. b)&pplication m!st be r!n e5plicitly within a java,compatible virt!al machine whereas applet loads and r!ns itself a!tomatically in a java,enabled browser. c)&pplication starts e5ec!tion with its main method whereas applet starts e5ec!tion with its init method. d)&pplication can r!n with or witho!t graphical !ser interface whereas applet m!st r!n within a graphical !ser interface. -) ;ifference between ?wing and &wt?&W' are heavy,weight componenets. ?wings are light,weight components. @ence swing wor+s faster than &W'..) What is a layo!t manager and what are different types of layo!t managers available in java &W'? & layo!t manager is an object that is !sed to organi7e components in a container. 'he different layo!ts are available are Dlow=ayo!t$ Aorder=ayo!t$ ard=ayo!t$ >rid=ayo!t and >ridAag=ayo!t.0) @ow are the elements of different layo!ts organi7ed? #lowLayout4 'he elements of a Dlow=ayo!t are organi7ed in a top to bottom$ left to right fashion.BorderLayout: 'he elements of a Aorder=ayo!t are organi7ed at the borders 3Forth$ ?o!th$ East and West) and the center of a container. $ardLayout: 'he elements of a ard=ayo!t are stac+ed$ on top of the other$ li+e a dec+ of cards. %ridLayout: 'he elements of a >rid=ayo!t are of e/!al si7e and are laid o!t !sing the s/!are of a grid.%ridBagLayout: 'he elements of a >ridAag=ayo!t are organi7ed according to a grid. @owever$ the elements are of different si7e and may occ!py more than one row or col!mn of the grid. #naddition$ the rows and col!mns may have different si7es. 'he default =ayo!t 1anager of Paneland Panel s!b classes is Dlow=ayo!t. 12) Why wo!ld yo! !se ?wingEtilities.invo+e&ndWait or ?wingEtilities.invo+e=ater? # want to !pdate a ?wing component b!t #)m not in a callbac+. #f # want the !pdate to happen immediately 3perhaps for a progress bar component) then#)d !se invo+e&ndWait. #f # don)t care when the !pdate occ!rs$ #)d !se invo+e=ater.11) What is an event and what are the models available for event handling? &n event is an event object that describes a state of change in a so!rce. #n other words$ event occ!rs when an action is generated$ li+e pressing b!tton$ clic+ing mo!se$ selecting a list$ etc. 'here are two types of models for handling events and they are4 a) event,inheritance model and b) event,delegation model 12) What is the difference between scrollbar and scrollpane? & ?crollbar is a omponent$ b!t not a ontainer whereas ?crollpane is aonatiner and handles its own events and perform its own scrolling.1") Why won)t the 6