You are on page 1of 10

Revision on Java

1) __________ represents an entity in the real world that can be distinctly identified.
A) A class
B) An object
C) A method
D) A data field

2) What are the two common characteristics shared by all objects?


A) Methods and interfaces.
B) State and behavior.
C) Methods and messages.
D) Interface and messages.

3) Which statements are not correct about Objects?


A) An Object is an instance of a class.
B) Objects can access both instance and static data.
C) All classes extend the Object class.
D) Objects do not permit encapsulation.

4) Which of the following is true?


A) An object receives copies of all instance variables, but shares method code.
B) An object receives copies of all instance variables and all methods.
C) An object receives copies of all methods, but shares instance variables.
D) An object shares both instance variables and methods with other objects.

5) ________ is invoked to create an object.


A) A constructor
B) The main method
C) A method with a return type
D) A method with the void return type

6) Which keyword represents object of the present class?


A) this
B) package
C) interface
D) final

7) What is the stored in the object obj in following lines of code?


box obj;

A) Memory address of allocated memory of object.


B) NULL
C) Any arbitrary pointer
D) Garbage
8) ______________ constructor is created when object of particular class is created.
A) Default
B) Parameterized
C) Copy
D) None of these

9) Object is an _________ of a class.


A) instance
B) implement
C) inheritance
D) invoke

10) The variables declared in a class for the use of all methods of the class are called
__________.
A) reference variables
B) objects
C) instance variables
D) None of these

11) An object is an instance of a __________.


A) program
B) class
C) method
D) data

12) Which of the following statements regarding static methods are correct?
i) Static methods are difficult to maintain, because you cannot change their implementation.
ii) Static methods can be called using an object reference to an object of the class in which
this method is defined.
iii) Static methods are always public, because they are defined at class-level.
iv) Static methods do not have direct access to non-static methods which are defined inside
the same class.
A) i and ii
B) ii and iv
C) iii and iv
D) i and iii

13) What is a class?


A) A class is a section of the hard disk reserved for object oriented programs.
B) A class is used as a template to create objects.
C) A class is a collection of objects.
D) A class is a section of computer memory containing objects.
14) Which of these keywords is used to make a class?
A) class
B) struct
C) cint
D) None of the mentioned

15) _______ is a construct that defines objects of the same type.


A) A class
B) An object
C) A method
D) A data field

16) In Java programs, the name of the class has to be ________________.


A) the same as the name of the file it is saved in
B) different from the name of the file it is saved in
C) all capital letters
D) all small letters

17) Which of the following may be part of a class definition?


A) Instance variables
B) Instance methods
C) Constructors
D) All of the above

18) Which of the following is a valid declaration of an object of class Box?


A) Box obj = new Box();
B) Box obj = new Box;
C) obj = new Box();
D) new Box obj;

19) Consider the following problem statement.

Write a program that takes as input the radius of a circle and finds the circumference and
area of thecircle.

Based on this problem statement, which of the following would most likely be chosen as the
class?
A) Circumference
B) Circle
C) Area
D) Radius
20) Which of the following are valid constructors within a class Test.
A) test() { }
B) Test() { }
C) void Test() { }
D) private final Test() { }

21) The default access specifier for the class members is _________.
A) public
B) private
C) protected
D) none of the above

22) Keyword _____ is always a reference to the object.


A) new
B) this
C) invoke
D) class

23) The ________ connects classes and objects.


A) dot
B) super
C) new
D) variable

24) The variable defined in class is called ________ variable.


A) local
B) minimum
C) instance
D) define

25) A special type of method that is used to initialize an object is called________.


A) constructor
B) destructor
C) modification
D) editor

26) A class is declared by use of the ________ keyword.


A) object
B) class
C) instance
D) method
27) The data or variables, defined within a class are called _______ variables.
A) object
B) class
C) instance
D) schema

28) In this example


class_var = new classname ( );

The class name followed by parentheses specifies the _________ for the class.
A) destructor
B) constructor
C) variables
D) memory

29) The dot operator is used to access the instance ______.


A) object
B) variable
C) model
D) value

30) A method can be called only on its ___________.


A) variable
B) object
C) method
D) delay

31) _________ keyword is used to invoke the current object.


A) new
B) that
C) this
D) me

32) A _______ object cannot be modified after it is created.


A) double
B) int
C) string
D) main

33) __________ is a special member function.


A) method
B) class
C) use defined function
D) constructor
34) Constructor will have the same name as ______________.
A) class
B) function
C) file
D) package

35) Class is considered ________ of an object and instance.


A) min
B) local
C) template
D) keyword

36) Which of these is correct way of calling a constructor having no parameters, of superclass A
by subclass B?
A) super(void);
B) superclass.();
C) super.A();
D) super();

37) The dot (.) operator connects the following two entities _____.
A) a class member and a class object
B) a class object and a class
C) a class and a member of that class.
D) a class object and a member of that class

38) Consider

1. public class MyClass{


2. public MyClass(){/*code*/}
3. // more code...
4. }

To instantiate MyClass, you would write ____________.


A) MyClass mc = new MyClass();
B) MyClass mc = MyClass();
C) MyClass mc = MyClass;
D) MyClass mc = new MyClass;

39) Consider
public class Test { }

What is the prototype of the default constructor?


A) public Test(void)
B) Test( )
C) Test(void)
D) public Test( )
40) What is the output of this program?
1. class box {
2. int width;
3. int height;
4. int length;
5. }
6. class mainclass {
7. public static void main(String args[]) {
8. box obj1 = new box();
9. box obj2 = new box();
10. obj1.height = 1;
11. obj1.length = 2;
12. obj1.width = 1;
13. obj2 = obj1;
14. System.out.println(obj2.height);
15. }
16. }

A) 1
B) 2
C) Runtime error
D) Garbage value

41) What is the output of this program?

1. class box {
2. int width;
3. int height;
4. int length;
5. }
6. class mainclass {
7. public static void main(String args[])
8. {
9. box obj = new box();
10. System.out.println(obj);
11. }
12. }

A) 0
B) 1
C) Runtime error
D) Garbage value

42) What is the expected output?


1. public class Profile {
2. private Profile(int w) {
3. System.out.print(w);
4. }
5. public static Profile() {
6. System.out.print (10);
7. }
8. public static void main(String args[]) {
9. Profile obj = new Profile(50);
10. }
11. }

A) 10
B) 10 50
C) Won't compile because of line (2), constructor can't be private
D) Won't compile because of line (5), constructor can't be static

43) The following code contains one compilation error, find it?
1. public class Test {
2. Test() { }
3. static void Test() {
4. this(); }
5. public static void main(String[] args) {
6. Test();
7. }
8. }

A) At line 2, constructor Tester must be marked public like its class


B) At line 4, constructor call
C) At line 5, compilation error, ambiguity problem, compiler can't determine whether a
constructor
D) At line 6

44) What is the expected output?


1. class MyClass{
2. MyClass(){
3. System.out.print("one");
4. }
5. public void myMethod(){
6. this();
7. System.out.print("two");
8. }
9. }
10. public class TestClass{
11. public static void main(String args[]){
12. MyClass obj = new MyClass();
13. obj.myMethod();
14. }
15. }

A) two one one


B) one one two
C) one Exception
D) Compilation Error

45) What is the expected output?

1. class MyClass{
2. int i;
3. int j;
4.
5. public MyClass(int i, int j){
6. this.i = i;
7. this.j = j;
8. }
9.
10. public void call(){
11. System.out.print("One");
12. }
13. }
14.
15. public class Test{
16. public static void main(String args[]){
17. MyClass m = new MyClass();
18. m.call();
19. }
20. }

A) One
B) Compilation fails due to an error on line 17
C) Compilation fails due to an error on line 18
D) Compilations succeed but no output.
46) What is the expected output?
1. public class D {
2. int i;
3. int j;
4. public D(int i,int j){
5. this.i=i;
6. this.j=j;
7. }
8. public void printName() {
9. System.out.println("Name-D");
10. }
11. }
12. public class Test{ //line 1
13. public static void main (String[] args){ //line 2
14. D d = new D(); //line 3
15. d.printName(); // line 4
16.
17. }
18. }

A) Name-D
B) Compilation fails due to an error on lines 14
C) Compilation fails due to an error on lines 15
D) Compilation succeed but no output

You might also like