0% found this document useful (0 votes)
2 views

java5

This document is an examination paper for the Object Oriented Programming - I course at Gujarat Technological University, scheduled for July 8, 2024. It includes various questions covering Java programming concepts, such as data types, method overloading, exception handling, and Java collections. The exam consists of multiple sections requiring programming, analysis of code, and theoretical explanations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

java5

This document is an examination paper for the Object Oriented Programming - I course at Gujarat Technological University, scheduled for July 8, 2024. It includes various questions covering Java programming concepts, such as data types, method overloading, exception handling, and Java collections. The exam consists of multiple sections requiring programming, analysis of code, and theoretical explanations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Enrolment No.

/Seat No_______________

GUJARAT TECHNOLOGICAL UNIVERSITY


BE - SEMESTER–IV (NEW) EXAMINATION – SUMMER 2024
Subject Code:3140705 Date:08-07-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) Answer in one word:(one mark for each) 03
I. Which integral type in Java has the exact range from -
2147483648 (-231) to 2147483647 (231-1).
II. The software for developing and running Java
programs.
III. It is similar to machine instructions but is
architecture neutral and can run on any platform that has
a Java Virtual Machine (JVM).
(b) Write a program that reads an integer and adds all the 04
digits in the integer. For example, if an integer is 932, the
sum of all its digits is 14.
Hint: Use the % operator to extract digits, and use the /
operator to remove the extracted digit. For instance, 932
% 10 = 2 and 932 / 10 = 93.

(c) Analyze following code pieces (assume they are properly 07


enclosed in class and main function) and write the
output/error (No justification is required): (one mark for
each)
I. int num = 5;
int x = 1;
for (int i = 1; i <= num; i++) {
x *= i;
}
System.out.println("x is " + x);

II. int[] nums = {1, 5, 3, 9, 7};

int m= 1;
int s= 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] > m) {
s = m;
m = nums[i];
} else if (nums[i] > s && nums[i] != m) {
s = nums[i];
}
}
System.out.println("s is: " + s);

P
A
G
III. int i=1,j=0,k=0;
if (i > k) {
if (j > k)
System.out.println("i and j are greater than k");
}
else
System.out.println("i is less than or equal to k");
IV. int x = 3, y = 3;
switch (x + 3) {
case 6: y = 1;
default: y += 1;
}
System.out.println("y is " + y);
V. class HelloWorld {
public static void main(String[] args) {
int[] numbers = new int[1];
numbers[0]=0;
m(numbers);
System.out.println("numbers[0] is" +
numbers[0]);
}
public static void m(int[] y) {
y[0] = 3;
}
}
VI. StringBuffer s1 = new StringBuffer("Complete");
s1.setCharAt(1,'i');
s1.setCharAt(7,'d');
System.out.println(s1);
VII. int Integer = 24;
char String ='I';
System.out.print(Integer);
System.out.print(String);

Q.2 (a) Describe the relationship between an object and its 03


defining class.
(b) Write java statements for following class: 04
public class Counter {
int c;
}
i. Declare a parameterized constructor to initialize
variable c.
ii. Declare instance method to increment c and return
updated value of c.

(c) Justify following: 07


i. In general, constructors should be public.
ii. Why main is declared as static.
iii. Why we do not declare destructors in java.
iv. There is no pointer in java.
OR
(c) Differentiate between following: 07
i. this keyword vs super keyword
ii. abstract class vs interface
Q.3 (a) Give definition of method overloading. 03

P
A
G
(b) i. Analyze following code pieces and write the 04
output/error and briefly justify output:
public class Test {
public static void main(String[] args) {
new Person().printPerson();
new Student().printPerson();
}
}

class Student extends Person {


@Override
public String getInfo() {
return "Student";
}
}

class Person {
public String getInfo() {
return "Person";
}

public void printPerson() {


System.out.println(getInfo());
}
}
ii. Given the following source code, which comment line
can be uncommented without introducing errors?
abstract class MyClass {
abstract void f();
final void g() {}
//final void h() {} // comment (1)
}
final class MyOtherClass extends MyClass {
public static void main(String[] args) {
MyClass mc = new MyOtherClass();
}
void f() {}
void h() {}
//void g() {} // comment (2)
}

(c) Discuss public, private, protected and default access 07


modifiers with examples.
OR
Q.3 (a) What is the final keyword? Give different uses of the final 03
keyword.
(b) Declare an interface called Function that has a method 04
named evaluate that takes an int parameter and returns an
int value.
Create a class called Half that implements the Function
interface. The implementation of the method evaluate()
should return the value obtained by dividing
the int argument by 2.
(c) What is an Exception? Explain Exception handling in 07
JAVA with the help of example.

P
A
G
Q.4 (a) How do keyword throw differ from throws in Exception 03
handling?
(b) Differentiate between a byte oriented and a character- 04
oriented stream.
(c) Explain binary I/O classes. Demonstrate java file I/O with 07
any I/O class to read a text file.
OR
Q.4 (a) Compare JavaFX with Swing and AWT. 03
(b) i. List any four UI controls in JavaFX. 04
ii. List any two Panes for Containing and Organizing
Nodes
(c) Write a program to demonstrate GUI application 07
development using JavaFX.
Q.5 (a) What are the differences between ArrayList and 03
LinkedList? Which list should you use to insert and delete
elements at the beginning of a list?
(b) What is Java Collection Framework? List four collection 04
classes?
(c) Give the name of class or interface that provides following 07
facility (Do not elaborate)(one mark for each)
i. Dynamic array to store the duplicate element of different
data types. It maintains the insertion order.
ii. Implements the last-in-first-out data structure.
iii. Implements the first-in-first-out data structure.
iv. Implements the first-in-first-out data structure and it
holds the elements or objects which are to be processed by
their priorities.
v. It represents the unordered set of elements which
doesn't allow us to store the duplicate items.
vi. It is a red-black tree-based implementation. It provides
an efficient means of storing key-value pairs in sorted
order.
vii. It allows us to store key and value pair, where keys
should be unique.
OR
Q.5 (a) Explain thread life cycle. 03
(b) What is the package? Explain steps to create a package 04
with example.
(c) Declare a class called Employee having employee_Id and 07
employee_Name as members.
Extend class Employee to have a subclass called
SalariedEmployee having designation and
monthly_salary as members. Define following:
- Required constructors
- Methods to insert, update and display all details of
employees.
- Method main for creating an array for storing these
details given as command line arguments and showing
usage of above methods.

***********

P
A
G

You might also like