You are on page 1of 2

MALNAD COLLEGE OF ENGINEERING, HASSAN - 573202

(An Autonomous Institution under VTU)


Activity-II: QUIZ Name : Even Semester 2018-19

Branch : Computer Science and Engineering Faculty-in-charge: Shruthi T R Date:


Course Title & Code: Object Oriented Programming with JAVA & CS403 Semester: IV
USN 4 M C I T Max. Marks:10 Time:
1. Answer all questions. Each question carries one mark.
1. Given this class, 6. A class Car and its subclass Yugo both have a
class Test method run() which was written by the programmer as
{ part of the class definition. If junker refers to an object of
int a; type Yugo, what will the following code do?
Test (int i) junker.show();
{
a=i; a) The show() method defined in Yugo will be called
} b) The show() method defined in Car will be called
Write a method called swap() that exchanges the
contents of the objects referred to by two Test
c) The compiler will complain that run() has been
defined twice.
object references.
Ans: d) Overloading will be used to pick which run() is
called.

Ans:

2. An inner class has access to the other members 7. Given the following hierarchy
of its enclosing class. True or False? class Alpha {……
class Beta extends Alpha {….
Ans: class Gamma extends Beta {….
In what order are the constructors for these classes
executed when Gamma object is instantiated?

Ans:

3. Show how to declare a method called sum() that 8. Given two interfaces called Alpha and Beta, show how
takes a variable number of int arguments(use a a class called Myclass specifies that it implements each.
return type of int) Ans:
Ans:
4. Predict the output of following Java Program. 9. Predict the output of following Java program

class Base { class Test extends Exception { }


final public void show() { class demo {
public static void main(String args[]) {
System.out.println("Base::show() called");}}
try {
class Derived extends Base { throw new Test();
}
public void show() { catch(Test t) {
System.out.println("Got the Test Exception");
System.out.println("Derived::show() called"); }} }
class Main { finally {
System.out.println("Inside finally block ");
public static void main(String[] args) { }
}
Base b = new Derived();; }
Ans:
b.show();
}}

Ans:

5. Which of these is a super class of all errors and 10. What is an exception?
exceptions in the Java language? Ans:
a) RunTimeExceptions
b) Throwable
c) Catchable
d) None of the above

Ans:

You might also like