Gujarat Technological University
Gujarat Technological University
___________
MARKS
Q.1 (a) What is the Java bytecode, and what is the extension of Java bytecode file? 03
Which software is needed to run Java bytecode?
(b) Describe syntax errors (compile errors), runtime errors, and logic errors by 04
giving suitable examples?
(c) Answer in brief (within 50 words): 07
I. Justify Java enables high performance.
II. Differentiate between while and do while loop?
III. How many times is the println statement executed?
for (int i = 0; i < 10; i++)
for (int j = 0; j < i; j++)
System.out.println(i * j);
IV. If the value of variable x is 1 then what will be returned by the
following expression:
x%2==0
Q.2 (a) What is the use of this keyword? How it is different from super keyword? 03
(b) (i) Given that Thing is a class, how many objects and how many reference 04
variables are created by the following code?
Thing item, stuff;
item = new Thing();
Thing entity = new Thing();
(ii) Examine following code. Write and justify output.
public class MyClass {
public static void main(String[] args) {
C c = new C();
System.out.println(c.max(12, 29));
}
}
class A {
int max(int x, int y) { if (x>y) return x; else return y; }
}
class B extends A{
int max(int x, int y) { return super.max(y, x) - 10; }
}
class C extends B {
int max(int x, int y) { return super.max(x+10, y+2); }
}
(c) Write a program that defines class named StopWatch. The class contains: 07
• Private data fields startTime and endTime with getter methods.
1
• no-arg constructor that initializes startTime with the current time.
• A method named start() that resets the startTime to the current time.
• A method named stop() that sets the endTime to the current time.
• A method named getElapsedTime() that returns the elapsed time for
the stopwatch in milliseconds.
• Declare object of StopWatch to demonstrate stop watch.
Hint: Use System.currentTimeMillis() to get current time in milliseconds.
OR
(c) Create a class called Employee that includes: 07
I. Three instance variables— id (type String), name (type String) and
monthly_salary (double).
II. A default constructor that initializes the three instance variables.
III. A setter and a getter method for each instance variable (for example
for id variable void setId(String id), String getId( )).
IV. displayEmployee() method for displaying employee details.
Write a driver class named EmployeeTest that demonstrates class Employee’s
capabilities. Create two Employee objects and display each object’s yearly
salary. Then give each Employee a 10% raise and display each Employee’s
yearly salary again.