Unit-2
I. Each Question Carries 1 Mark.
1) Class is ____for an object?
a) Template b) Instance c) Structure d) None
2) Which operator dynamically allocates memory for an object?
a) New b) Static c) Malloc d) Calloc
3) _______Initializes an object immediately upon creation.
a) Constructor b) Destructor c) Main d) None
4) Which keyword is used inside any method to refer to the current object?
a) This b) Super c) Volatile d) None
5) When no reference to an object exist, the memory occupied by the object can be
Reclaimed by.
a) Garbage Collection b) Destructor c) Free d) None
6) Which method is invoked before an object is reclaimed by the garbage collector?
A) Finalize b) Initialize c) gc( ) d) None
7) Can we overload Constructors?
a) True b) False c) Sometimes d) None
8) Can we overload Methods?
a) True b) False c) Sometimes d) None
9) Java passes objects by?
a) Call by reference b) Call By value c) Call By Name d) None
10) Whenever a subclass needs to refer its immediate super class, it can do so by __?
a) Super b) This c) static d) None
11) A call to overridden function is resolved at run time?
a) Dynamic Method dispatch b) Static method Dispatch
c) Dynamic Memory Dispatch d) None
12) Overriding of methods is an example of ______
a) Polymorphism b) Inheritance c) Exception d) None
13) Which class can’t be directly instantiated with the new operator?
a) Abstract b) Final c) Super d) None
14) In a class if there is at least one abstract method then the class is ___?
a) Abstract b) Final c) Super d) None
15) Which class can’t be subclassed?
a) Final b) Abstract c) Super d) None
16) Which method can’t be overridden_______?
a) Final b) Abstract c) Super d) None
17) Which class is the Super class for the all the classes?
a) Object b) Class c) Super d) None
18) What are the containers for the classes?
a) Packages b) Interfaces c) Abstract d) None
19) Which modifier can be accessed from anywhere?
a) public b) private c) protected d) None
20) No modifier specifier can be accessed with in the same package?
a) Yes b) No
21) Protected modifier can be accessed by subclass in different package?
a) Yes b) No
22) Protected modifier can be accessed by non-subclass in different package?
a) No b) Yes
23) Which modifier can’t be visible outside of its class?
a) private b) public c) protected d) None
24) Which statement is use to bring certain classes or entire package into visibility?
a) Import b) Include c) package d) None
25) A____________ constructor does not take any parameter
a) new b) default c) old d) class
I. Answer – 1 Mark.
1. B 2. A 3. A 4. A 5. A 6. A 7. A
8. A 9. A 10. A 11. A 12. A 13. A 14. A
15. A 16. A 17. A 18. A 19. A 20. B 21. A
22. A 23. A 24. A 25. A
II. Each Question Carries 2 Mark.
1) class test
{ private int b;
}
class testdemo
{ void aa()
{ test t = new test();
t. b = 10;
System.out.println(t.b);
}
}
a) Error b) 10 c) 0 d) None
2) class A
{ }
class B extends A
class A is called
a) super class b) base class c) subclass d)child class
3) Static methods can run only other static methods. Variables are three types such as class variables, loca variables, instance variables .
a. True b) False
4) 4.Static data must access only static data. Variables defined with in the methods are called loca variables. Their scope is limited to with in the method jin which they are defined.
a. True b False
5) class A {final void add() { System.out.println(“This is a final method”); }
class B extends A {void add() { ……..} }
a) Can’t override final method b) Can override the final method
c) Runtime error d) None
6) final class A {//…… }
class B extends A { // ……. }
a) can’t subclass A b) can subclass A. c) Runtime error d) None
1) A clas is defined by the class key word followed by the name of class, by default clases inherit from Object class. Object class is the subclass of all classes.
a) True b) False
8). A class is a _________ which represents a __________ object.
a) framework, general b) general, framework c) instance, static d) None
9) Instance of the classes represent individual objects, a class can contain properties and methods. Java file should be the same as the class name.
a) True b) False
10) A constructor which does not take any parameter is called as default constructor, It is __________ provided by java.
a) explicitly b) implicitly c) runtime d) None
1) Variables declared out side the method definitions are called __________.
Generally they are defined immediately after the first line of the class definition.
a) class variables b) local variables c) instance variables d) None
2) class variables apply to a class as a whole. All instances of the class have to access to the same copy. The static keyword is used to declare a class variable
a) False b) True
3) return key word has to be used with in the body of the method to return the value. The name of the method and the list of parameters is called as the __________of the method.
a) Argument b) signature c) return type d) None
4) The declaration of local variable hides the value of instance of class variables. The values of instance or class variables can be accessed by using this keyword.
a) True b) False
5) Instance methods can be used only with respect to the instance of the class. An object has to be created in order to use the instance method.
a) True b) False
II. Answer – 2 Mark.
1. A 2. B 3. A 4. A 5. A 6. A 7. A
8. A 9. A 10. B 11. C 12. B 13. B 14. A
15.A
III. Each Question Carries 4 Mark.
1) What is the output ?
class MyStatic
{
static int y;
static void show(){ System.out.println("y = "+y);
}
class demo
{ public static void main(String args[])
{
MyStatic.y = 10;
MyStatic.show();
}
}
a) 10 b) Run Time Error c) Compile time Err d) None
2) Methods are defined as
i) Return type ii) Name of the Method
iii) A list of Parameters iv) Body of the method
a) one i b) ii, iii c) all d) None
3) Select true statements
i) When a variable is referred with in a method, java checks for the definition of the variable.
ii) if the variable is not local variables, that is if it is not defined within the current method
then java checks for the definition of that variable as an instance or class variables.
a) only i b) only ii c) Both d) None
4) i.) The lack of static key word in fornt of a method makes it an instance method.
ii) java supplies wrapper classes for each of the basic data types.
iii) The wrapper classes provide class methods to perform conversions from object to primitive data type and vice versa.
a) i. b) ii c) All d) None
5) class A
{ private int a; protected int b; public int c; }
class B extends A { }
in class B how many variables can be accessed.
a) only one b) only two c) All d) None
6) Select true statements
i) function overloading is nothing but the number of arguments or the type of arguments are to be different for creating two or
more methods with the same name.
ii) The return types of the methods can be different as long as the method signature is different.
iii) When the same method name is used in both the subclass and super class with the same signature is called function
overriding.
a) i, ii b) ii , iii c) i, ii, iii d) None
7) i) constructor methods have the same name as the name of the class
ii) constructor does not return a value
iii) it can be overloaded
iv) Typically they are used to set initial values to instance variables
a) i, ii b) i, ii, iii c) All d) None
8) i) The key word extends is used to implement inheritance.
ii) The key word extends is followed by name of the super class
iii) In Java Object class is at the top of the hierarchy of the classes.
a) only I b) only ii c) All d) None
9) i) a package is collection of classes and interfaces
ii) java.io package contains classes and interfaces for various kinds of input and out.
iii) package defines a boundary to see how classes and interfaces interact with one another.
a) only i b) only iii c) i, ii, iii d) None
10) i) classpath variable plays significant role in locating classes.
ii) if class path is not set, java will look for the classes in the current directory and the default directory.
iii) if class path is specified then java will look those directories which are specified with class path.
a) i, ii, iii b) only i c) only i, ii d) None
III. Answer – 4 Mark.
1. A 2. A 3. C 4. B 5. B 6. C 7. C
8. C 9. C 10. A