100% found this document useful (1 vote)
2K views2 pages

OOP Questions For Exit Exam

The document contains 10 multiple choice questions about object-oriented programming concepts in Java. Some key topics covered include constructors, static vs instance methods, access modifiers, inheritance, polymorphism, and exceptions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views2 pages

OOP Questions For Exit Exam

The document contains 10 multiple choice questions about object-oriented programming concepts in Java. Some key topics covered include constructors, static vs instance methods, access modifiers, inheritance, polymorphism, and exceptions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

OOP Questions

1. Which one of the following statements is not true?


A) Constructors must have the same name as the class.
B) The “this” keyword is used to invoke overloaded constructors of different classes.
C) Static methods can be inherited but cannot be overridden in a subclass.
D) Attempting to invoke a subclass-only method directly on a superclass reference is a compilation error.
2. How do we access an instance variable from a static method in Java within the same class?
A) Using a variable name by itself.
B) Using the object reference variable followed by a dot (.) and the variable name.
C) Using the class name followed by a dot (.) and the variable name.
D) There is no way to access an instance variable from the context of static method.
3. A class design requires that a particular class member method must be accessible by any subclasses of
this class, but otherwise not by classes which are not members of the same package. What should be
done to achieve this?
A) The method should be declared as public.
B) The method should be declared as protected.
C) The method should use the default access modifier.
D) The method should be declared as private.
4. Which one of the following statements is not true in Java?
A) A default constructor is provided automatically if no constructors are explicitly declared in the class.
B) A local variable defined in a particular method can be visible anywhere within that method.
C) A final class cannot be extended to create a subclass.
D) Constructors of a class are not inherited.
5. Which one of the following method header represents a method that cannot be overridden in a subclass?
A) public int sum(int x, int y) C) public abstract void display(int x)
B) public final void display() D)public voiddisplay(String msg)
6. Which one of the following statements is not true?
A) IOException (package java.io) is unchecked exception.
B) Call to a static method is always resolved at compile time.
C) Dynamic binding can be applied to abstract methods.
D) Private and static methods are implicitly final methods.
7. Which statements are most accurate regarding the following classes? (Assume that both classes are
defined within the same public class Parent { public class Child extends Parent {
package) private int i; private int k;
protected int j; protected int m;
} }
A) An object of Child contains data fields i, j, k, and m
B) An object of Child contains data fields j, k, and m only.
C) An object of Child contains data fields j and m only.
D) An object of Child contains data fields k and m only.
8. If a private method in a subclass has the same name as a method in its superclass with different
parameter types, then which one of the following is correct?
A) The method is overridden. C) The two methods are completely unrelated.
B) The method is overloaded. D) Compile time error will occur.
9. Which one of the following statements regarding abstract classes and methods is not true?
A) A class that contains abstract methods must be abstract.
B) An abstract method cannot be contained in a non-abstract class.
C) An abstract class can have instances created using the constructor of the abstract class.
D) It is possible to declare a class as abstract that contains no abstract methods.

10. Does the following code throw an exception? If so, what exception type does it throw?

public class Test {


A)Yes it throws ArithmeticException
public static void main(String[] args) {
Object o = new String();
B)Yes it throws NullPointerException
String s = (String)o;
C)Yes it throws ClassCastException
}
D)No it does not throw any exception
}

You might also like