Shanmugasundari.files.wordpress.com



VELAMMAL COLLEGE OF ENGINEERING AND TECHNOLOGY, MADURAI – 625 009Department of Information TechnologyINTERNAL ASSESSMENT – I-QUESTION BANK WITH ANSWER KEYBranchITYear/Sem./Sec.II/III/-Course CodeCS8392Date & Session03.09.2020 & ANCourse NameObject Oriented ProgrammingMax. marks50Course InchargeMrs.N.Shanmuga SundariTime01:30 HoursPART A (Answer All Questions) (8 X 2 = 16)KCOMarks1.What is meant by ‘static’ in java?Static?is a non-access modifier in Java which is applicable for the following:VariablesblocksMethodsTo create a static member (block, variable, method, nested class), precede its declaration with the keyword?static. When a member is declared static, it can be accessed by its class irrespective of object.?K1CO12What is the difference between a constructor and a method?Constructor is used to initialize an object whereas method is used to exhibits functionality of an object.Constructors are invoked implicitly whereas methods are invoked explicitly.Constructor does not return any value where the method may/may not return a value.In case constructor is not present, a default constructor is provided by java compiler. In the case of a method, no default method is provided.Constructor should be of the same name as that of class. Method name should not be of the same name as that of class.K1CO12 List the features of JavaSimpleSecurePortableObject-orientedRobust MultithreadedArchitecture-neutralInterpretedHigh performanceDistributedDynamicK1CO122.What is JVM?JVM (Java Virtual Machine) acts as a run-time engine to run Java applications. JVM is the one that actually calls the main method present in a java code. JVM is a part of JRE.A programmer can develop Java code on one system and run it on any other Java enabled system without any adjustment. This is all possible because of JVM.K1CO12List the tools available in JDKBasic Tools (javac, java, javadoc, apt, appletviewer, jar, jdb, javah, javap, extcheck)Security Tools (keytool, jarsigner, policytool, kinit, klist, ktab)Internationalization Tools (native2ascii)Remote Method Invocation (RMI) Tools (rmic, rmiregistry, rmid, serialver)K1CO12What is JRE?The Java Runtime Environment (JRE) is a set of software tools for development of Java applications. It combines the Java Virtual Machine (JVM), platform core classes and supporting libraries.K1CO123.Define access specifier and its rights tableRestrict the scope of a class, constructor, variable, method or data member.Access Modifier within class within package outside package (inherited class) outside package Private Y N N N Default Y Y N N Protected Y Y Y N Public Y Y Y Y K1CO12Define JIC (Just in –time compiler).A compiler that converts program source code into native machine code just before the program is run. In the case of Java, a JIT compiler converts Java's intermediate language (byte code) into native machine code as needed.K1CO12What is the meaning of public static void main(String a[])public: This makes the main method public that means that we can call the method from outside the class.static: We do not need to create object for static methods to run. They can run itself.void: It does not return anything.main: It is the method name. This is the entry point method from which the JVM can run your program.(String[] args): Used for command line arguments that are passed as strings.K1CO124.What is a class, object and method?Class: A class is a user defined blueprint or prototype from which objects are created. It represents the set of properties or methods that are common to all objects of one typesyntax:Access modifier class classname{}Object: It is a basic unit of Object Oriented Programming and represents the real life entities. A typical Java program creates many objects.syntax: classname objname=new classname();Method: A method is a set of code which is referred to by name and can be called (invoked) at any point in a program simply by utilizing the method's name.syntax :Access modifier returntype methodname(params){}K1CO12What are a class variable, member variable and local variable?Local variables are not visible in outside the method. Instance variables are declared in a class, but outside a method. They are also called member or field variables. Variables which are created exclusively for class and irrespective of object are known as class variable. Eg static variablesK1CO12What is encapsulation? Explain with an example.Encapsulation.?This is the practice of keeping fields within a class private, then providing access to them via public methods. It’s a protective barrier that keeps the data and code safe within the class itself.EG: Power steering mechanism of a car. Power steering of a car is a complex system, which internally have lots of components tightly coupled together, But to the external world there is only one interface is available and rest of the complexity is hidden.K1CO125.What is meant by abstraction?Abstraction means using simple things to represent complexity. Eg: We all know how to turn the TV on, but we don’t need to know how it works in order to enjoy it.K1CO12What is the difference between static and non static variables?Non-static variable: Eg int a;Memory is allocated for these variable whenever an object is createdMemory is allocated multiple times whenever a new object is created.Non-static variable can access with object reference.syntax: obj_ref.variable_nameStatic variable:Eg:static int a;Memory is allocated for this variable at the time of loading of the class. Memory location can be sharable by every object reference or same class.Memory is allocated for these variable only once in the program.Static variable can access with class reference. syntax: class_name.variable_nameK1CO12What is a constructor?Constructor is a special member method which will be called automatically whenever object is created.Rules: Constructor name must be similar to name of the class.Constructor should not return any value even void also and it should not be staticConstructors will not be inherited from one class to another classConstructors will not be inherited from one class to another classK1CO126.What do you mean by command line parameters?The command line argument is the argument passed to a program at the time when you run it. In java they are stored as string in String array passed to the args parameter of main() method. E g: String args[]K1CO12What is package? Write the syntax for importing package in JAVA file with exampleA package is a collection of similar types of classes, interfaces and sub-packages. If we want to develop any class or interface which is common for most of the java programs than such common classes and interfaces must be place in a package.Syntax: import pakagename.classname; Eg: package mypack.A;K1CO12Define Array and how it is defined in JAVAAn array is a group of like-typed variables that are referred to by a common name.In Java all arrays are dynamically allocatedtype var-name[] = new type [size];K1CO127.Define wrapper class and ExampleFor each and every fundamental data type there exist a pre-defined class, Such predefined class is known as wrapper class. The purpose of wrapper class is to convert numeric string data into numerical or fundamental data.Example:for Integer: int x=Integer.parseInt(String);for float: float x=Float.parseFloat(String);for double: double x=Double.parseDouble(String);K1CO12What are literals? Write the types of literals support y JAVAAny constant value which can be assigned to the variable is called as literal/constant. Integral, Floating point, char, stringK1CO12Can a JAVA source file be saved using other than the class file justifyYes, JAVA source code file can be saved with any other name, not same as your main class name if class is not public. Class file will be generated with class name in the file rather than file name.K1CO128.Define Garbage collections The process of removing unused objects from heap memory is known as Garbage collection. In java, the garbage collection is automatic. There are many ways:By nulling the reference. syntax :objname=nullBy assigning a reference to another.syntax:obj1=obj2(Now obj1 is ready for garbage collection)By anonymous object etc. syntax: finalize() and gc().K1CO12Define Constructor Overloading:Constructor overloading in Java is a technique of having more than one constructor with different parameter lists. They are arranged in a way that each constructor performs a different task. They are differentiated by the compiler by the number of parameters in the list and their types.EG: class A{A(){ },A(int a){}}K1CO12Define Destructor. How it is used in JAVAA destructor is a special method called automatically during the destruction of an object. Actions executed in the destructor include the following: Recovering the heap space allocated during the lifetime of an object. Closing file or database connections. Releasing network resources.There are many ways:By nulling the reference. syntax: objname=nullBy assigning a reference to another.syntax:obj1=obj2(Now obj1 is ready for garbage collection)By anonymous object etc. syntax: finalize() and gc().K1CO12PART B (Answer All Questions) (2 X 13 = 26)10.Write a Java program to read 5 subject marks of a student and calculate the total and grade. The grade system is as follows.Letter GradeGrade PointsMarks RangeO (Outstanding)1091 – 100A+ (Excellent)981 – 90A (Very Good)871 – 80B+ (Good)761 – 70B (Average)650 – 60RA0< 50Objective(1),Concepts Involved(class, object, syntax, access specifiers and tale, selection statement/control statement)-5,Program-6,Sample Output(1)K3CO11310.a. Define a class named COMPLEX for representing complex numbers that contains necessary data members and member functions. A complex number has the general form a + ib, where a is the real part and b is the imaginary part (i stands for imaginary). Include methods for all the four basic arithmetic operators.(9)b. Write a Java program that determines the number of days in a month.(4)Objective(1),Concepts Involved(class, object, syntax, access specifiers and tale, selection statement/control statement)-5,Program-6,Sample Output(1)K3CO11310.i)Make use of an example JAVA program to explain the concepts of Object oriented principles (9)principles with explanation(5),Eg(4)ii)Explain in detail about features of JAVA (4)Features each(0.5)-8 features requiredK3CO11310.Develop the Internal mark calculation system based on the attendance percentage using Java. Get the student name, register number, total number of working days in the semester and Number of days present. Calculate attendance percentage of the students and award attendance mark based on the following condition. Attendance percentage >=90 – 5 MarksAttendance percentage >=80 and < 90 – 4 MarksAttendance percentage >=75 and < 80 – 3 MarksAttendance percentage < 75 - 0 MarksObjective(1),Concepts Involved(class, object, syntax, access specifiers and tale, selection statement/control statement)-5,Program-6,Sample Output(1)K3CO11310(i) Develop a Java application using packages to implement the following currency converter – Dollar to Indian Rupees, Euro to Indian Rupees, Yen to Indian Rupees and vice versa.(6)(ii) Write a Java program to create a Package “YEAR_I” which has a class YearIMarks (members – sub1mark, sub2mark). Create another package “YEAR_II” which has a class YearIIMarks (members – sub3mark, sub4mark ). Create n objects of Student class (having rollNumber, name, YearIMarks and YearIIMarks). Calculate the Grade (‘Pass’ > =50 else ‘Fail’) for each subject and display the result of the student in proper format.(7)Objective(1),Concepts Involved(class, object, syntax, access specifiers and tale, package and its syntax)-5,Program-6,Sample Output(1)K3CO11311.i) Write a Java program that illustrates how run time polymorphism is achieved.(4)Definition(2),Program(2)(ii) Explain in detail about hierarchical and multilevel inheritance in java and demonstrate execution order of constructor in these types(9)hierarchical(definition, diagram, syntax, program)-4,Multilevel( definition, diagram, syntax ,program)-5K3CO21311.Create a Java class Shape with constructor to initialize the one parameter “dimension”. Now create three subclasses of Shape with following methods:i)“Circle” with methods to calculate the area and circumference of the circle with dimension as radius.ii)“Square” with methods to calculate the area and length of diagonal of square with dimension as length of one side.iii)“Sphere” with methods to calculate the volume and surface area of sphere with dimension as radius of sphere. Write appropriate main method to create object of each class and test every method.Objective(1),Concepts Involved(Inheritance, types of inheritance and its syntax, diagram)-5,Program-6,Sample Output(1)K3CO21311.Create a Java application to find the area of different shapes using abstract class. Use the abstract class Shape that include two integers and an empty method named printArea(). Construct the classes Rectangle, Triangle and Circle inherited from the class Shape. The Derived classes should include only the method printArea() that print the area of the given shape.Objective(1),Concepts Involved(Abstract class, Abstract method, syntax for both, comparison between normal class and abstract class)-5,Program-6,Sample Output(1)K3CO21311.Develop a Java application with employee class includes emp_name, emp_id, address, mail_id, mobile_no as members. Inherit the classes Programmer, Assistant Professor from employee class. Add Basic Pay as the member of all the inherited classes with 97% of BP as DA, 10% of BP as HRA, 12% of BP as PF, 0.1% of BP for staff club fund. Generate the pay slips for the employees with their gross and net salary.Objective(1),Concepts Involved(Inheritance, types of inheritance and its syntax, diagram)-5,Program-6,Sample Output(1)K3CO213PART C (Answer All Questions) (1 X 8 = 8)12. Define Inheritance. With diagrammatic illustration and java program explain each types of inheritance in detail.Definition(1), types of inheritance and its syntax, diagram(2),program(5)K3CO2812.Write a java class called ‘student’ with name, and roll no. Write a class ‘Result’ to get Marks of 3 subjects and another class “Sports’ to get the points obtained in sports. Calculate the total Marks and displays the result (pass or fail) with points obtained in sports for three students using inheritance and constructor.Objective(0.5),Concepts Involved(Inheritance, types of inheritance and its syntax, diagram)-2,Program-5,Sample Output(0.5)K3CO2812.Define an abstract class “car” with members reg_no, model, reg_date. Define two subclasses of this class – “transportVehicles ” (validity_no, start_date, period) and “privateVehicle ” (owner_name, owner_address). Define appropriate constructors. Create n objects which could be of either transportVehicles or privateVehicle class by asking the user’s choice. Display details of all “privateVehicle” objects and all “transportVehicles” objects.Objective(0.5),Concepts Involved(Inheritance, types of inheritance and its syntax, diagram, abstract class)-2,Program-5,Sample Output(0.5)K3CO2812.Explain in detail about abstract class and abstract methods. Compare class and abstract class. Illustrate with an example.Abstract class-2(Definition, syntax),abstract method (definition, syntax) , comparison(2),program(2)K3CO28Course Incharge(Mrs.N.Shanmuga Sundari)Module Coordinator(Mrs.D.Anandhavalli)HoD/IT(Dr.R.Perumalraja) ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download