Seat No.: ________ Enrolment No.
___________
GUJARAT TECHNOLOGICAL UNIVERSITY
BE - SEMESTER–IV (NEW) EXAMINATION – WINTER 2023
Subject Code:3140705 Date:31-01-2024
Subject Name: Object Oriented Programming -I
Time: 10:30 AM TO 01:00 PM Total Marks:70
Instructions:
1. Attempt all questions.
2. Make suitable assumptions wherever necessary.
3. Figures to the right indicate full marks.
4. Simple and non-programmable scientific calculators are allowed.
MARKS
Q.1 (a) How java supports platform independency? What is the role of JVM in it? 03
(b) Write a program which displays first n prime number? Where is n provided 04
by user as command line argument?
(c) Write a program which declare integer array of 10 elements? Initialize array 07
and define following methods with the specified header:
(i) public static int add(int [] array) print addition of all element of array.
(ii) public static int max(int [] array) print maximum element of array.
(ii) public static int search(int [] array, int key) search element key in array
and return index of it. If element is not found method will return -1.
Q.2 (a) Describe the relationship between an object and its defining class? 03
(b) Analyze following code. Validate and explain output of code. If any error 04
exists, indicate portion. Suggest code to eliminate error:
public class Circle {
private double radius;
public static void main(String args[]){
Circle c1=new Circle(2);
[Link]("Area "+[Link]());
B b1=new B(2, 2);
[Link]("Area "+[Link]());
}
public Circle(double radius) {
radius = radius;
}
public double getRadius() {
return radius;
}
public double getArea() {
return radius * radius * [Link];
}
}
class B extends Circle {
private double length;
B(){}
B(double radius, double length) {
length = length;
}
public double getArea() {
return ([Link]() * length);
}
}
(c) Design a java class Rectangle which contains following field and methods: 07
(i) Field: length, width: int
(ii) Default Constructor: initialize all fields with 0 value
(iii) Method: int getArea() will return area of rectangle.
1
OR
(c) Answer in brief(within two lines): 07
(i) If a method defined in a subclass has the same signature as a method in its
superclass with the
same return type, is the method overridden or overloaded?
(ii) How do you invoke an overridden superclass method from a subclass?
(iii) What is the purpose of "this" keyword?
(iv) Differentiate between following statements:
int a=3;
Integer b=new Integer(3);
(v) Which java keyword is used to prevent inheritance (prevent class to be
extended)?
(vi) Can we create reference of interface. If we can create, then what is the
use of it?
(vii) What is the difference between a String in Java and String in C/C++?
Q.3 (a) Discuss benefits of multithreading? 03
(b) Develop a program which stores name of districts in Gujrat in array of String. 04
The array specified capacity to store 5 districts. The user will be able to print
name of district based on array index e.g. (0 will print Ahemdabad). If the
specified index is out of bounds, program will display the message Out of
Bounds.
(c) Characterize the two ways of implementing thread in Java? Illustrate each 07
method by example?
OR
Q.3 (a) Explain the use of finally. Show the type of code usually kept in finally? 03
(b) Distinguish unchecked exception and checked exception? Give example of 04
each type of exception?
(c) Implement java code to take some (say 10) Strings from users. Put all the 07
input Strings in an array (String name[]). Provide implementation of
following methods:
(i)search(String s) will return index of String passed in method if String S is
found in name, otherwise return -1.
(ii)sort() will print sorted String array to user
Q.4 (a) Write a program to find out whether the given number is palindrome or not? 03
(b) Outline the use of throw in exception handling with example. 04
(c) Give Definitions: static, finalize, final 07
OR
Q.4 (a) Elaborate the role of java garbage collector. 03
(b) State four similarities between Interfaces and Classes. 04
(c) Differentiate between ArrayList and LinkedList? Which list should you use 07
to insert and delete elements at the beginning of a list? What methods are in
LinkedList but not in ArrayList?
Q.5 (a) List various classes for Binary Input Output? 03
(b) Characterize the role of Iterator interface? 04
(c) Explain DataInputStream and DataOutputStream Classes? Implement a java 07
program to demonstrate any one of them?
OR
Q.5 (a) What do you understand by JavaFX? How it is different from AWT? 03
(b) Explain ArrayList Class with its methods? 04
(c) Design and develop EMI Calculator using JavaFX? The user will enter a loan 07
amount, annual interest
2
rate, and number of years and click the Calculate button to get EMI and total
payment ? formula is
EMI= P*r*(1+r)n/((1+r)n-1)
P is Principal Loan Amount
r is rate of interest calculated on monthly basis. (i.e., r = Rate of Annual
interest/12/100. If rate of interest is 10.5% per annum, then r =
10.5/12/100=0.00875)
n is loan term / tenure / duration in number of months?
***********