NOTE: There are 9 Questions in all.
· Question 1 is compulsory and carries 20 marks.
· Out of the remaining EIGHT Questions answer any FIVE Questions. Each question carries 16 marks.
· Any required data not explicitly given, may be suitably assumed and stated.
Q.1 State which of the statement is true and which are false. (2x10)
a. Inheritance is implemented using “inherits” keyword.
c. The objects of class can be created without using the “new” operator.
d. *this is used to refer the current object.
f. A variable declared as final cannot be modified.
g. The length of an array arr[] is determined as arr.length;.
h. The scope of the inner class in the nested class is fully within the scope of its enclosing class.
i. super() keyword is used to call the superclass constructor.
j. Throwable class is at the top of the exception class hierarchy.
Answer any FIVE Questions out of EIGHT Questions.
Each question carries 16 marks.
Q.2 a. What is the output of the following code segments? Justify your answers.
(i) class A{
public static void main(String args[ ])
{
int a,b;
for(a=1,b=4;a<b; a++,b--)
{
System.out.println(“a =”+a);
System.out.println(“b =”+b);
}
}
};
(ii) class A{
static int a= 2;
static int b= 3;
static void fun()
{
System.out.println(“a = ”+ a);
}
public static void main(String args[])
{
fun();
System.out.println(“b = ” + A.b);
}
};
(iii) class A
{
int i,j;
A(int a, int b)
{
i=a; j=b;
}
void show() {System.out.println(“i=”+i+“j = ”+j); }
}
class B extends A
{
int j;
B(int a, int b, int c )
{
super(a, b);
j=c;
}
void show() { super.show();
System.out.println(“j = ”+j);}
public static void main(String a[]){
A oba;
B obb = new B(10,20,30);
Obb.show();
}
};
(iv) interface A
{
void fun(int);
};
class B inherits A{
void fun(int a=2)
{
System.out.println(“a = ”+a);
}
public static void main(String a[])
{
A oba = new A();
B obb = new B();
obb.fun(3);
}
}; (3*4=12)
b. What is an abstract class? Give an example. (4)
Q.3 a. Write a Java program to implement:
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1 (6)
b. Identify and correct the errors in the following segments:
(i) class A
{
public static void main(string []a){
int x = 1;
{
int x = 2;
System.out.print(x);
}
}
};
(ii) int arr[] = new int [10];
System.out.println(arr[10]);
(iii) loop1:for(int i=1;i<=5;i++)
{
for(int j=1;j<=2;j++)
{
if(j== 1) break loop1;
System.out.println(“j “+j);
}
}
System.out.println(“EXIT”);
(iv) int x =2;
int(X==2)
system.out.Println(“2”);
else
System.out.print(“ ”);
(v) Boolean b=t; (2*5=10)
Q.4 a. What is the meant by static variable and static method. Give an example? (6)
b. How is type conversion and casting implemented in Java? (4)
c. Explain function overloading with the help of an example? (6)
Q.5 a. Write a Java program to copy the contents of the source file to the destination file using command line arguments. i.e. java Copy <sourcefile> <destination file> (10)
b. How is multiple inheritance implemented in Java? (6)
Q.6 a. Create a class that contains an array of integers containing numbers 1,2,..5 with member methods print() which prints the elements of array and reverse() that reverses the elements of array using recursion. Write a Java program to implement it. (10)
b. What is the difference between an interface and a class. (3)
c. What is a package and how is it created? (3)
Q.7 a. What is the importance of bytecode in Java? (2)
b. What is the importance of final keyword in inheritance. (3)
c. Create a class TwoDim which contains x and y co-ordinates as int. Define the default constructor, parameterized constructor and void print() to print the co-ordinates. Now reuse this class in ThreeDim adding a new dimension as z of type int. Define the constructors for the subclass and override the method void print() in the subclass. Implement main() to show dynamic polymorphism. (4+4+3)
Q.8 a. List the benefits of exception handling over conventional error processing. Differentiate between catching and throwing an exception. (6)
b. Write a Java program to find the highest common factor of two numbers. (6)
c. (i) What is the difference between :
A ob;
and
A ob =new A();
(ii) Identify errors and rectify them:
String s1 = “java”;
String s2 = “paper”;
String s3 = s1+s2;
System.out.println(s1.length + s2.length + s3.length); (2+2)
Q.9 Write short notes on the following:
(i) OOP principles
(ii) Java applets
(iii) Bitwise operators >> and >>>
(iv) Early binding and late binding. (4*4 = 16)