CHAPTER-08: Classes and Objects
in Java
Textbook Solution
1. Which of the following defines attributes and methods?
a. Class
b. Object
c. Instance
d. Variable
2. Which of the following keyword is used to declare Class variables and
class methods?
a. static
b. private
c. public
d. package
3. Which of the following operator creates an object and returns its
reference?
a. dot (.)
b. new
c. colon (:)
d. assignment (=)
4. Which of the following method can be called without creating an
instance of a class?
a. Instance method
b. Class method
c. Constructor method
d. All of these
5. Which of the following refers more than one method having same name
but different
parameters?
a. Overloaded methods
b. Overridden methods
c. Duplicate methods
d. All of these
6. Which method is invoked automatically with creation of an object?
a. Instance method
b. Constructor
c. Class method
d. All of these
7. Which of the following is the keyword used to refer a superclass
constructor in subclass
constructor?
a. extends
b. super
c. name of the superclass
d. new
8. Which of the following is used to invoke an instance method in Java?
a. The name of the object, colon (:) and the name of the method
b. The name of the object, dot (.) and the name of the method
c. The name of the class, colon (:) and the name of the method
d. The name of the class, dot (.) and the name of the method
9. Which of the following is accessible by instance methods?
a. Only instance variables
b. Only class variables
c. Both (A) and (B)
d. None of these (d)
10. When methods in the superclass and subclass have same name and
signature, what are
they called ?
a. Overloaded methods
b. Overridden methods (b)
c. Inherited methods
d. All of these
Exam Oriented MCQs
1. What does a class contain?
a) Data & Method b) Data & Program code
c) Only Data d) Only program code
2. In class, Data is referred to as ………….
a) Attributes b) behavior c) state d) function
3. In Java functions referred to as …………..
a) Attributes b) behavior c) state d) Method
4. When a program contains 2 or more classes, only one class can contain the
…………method.
a) main( ) b) String( ) c) class d) private
5. What is a template for multiple objects with similar features?
a) class b) Method c) Attribute d) Behavior
6. In Java, a class is defined using which keyword?
a) Public b) class c) name d) Attribute
7. Write down the syntax for defining a class.
Ans. class <ClassName> {<Variables> <Methods> }
8. Every class is made up with how many components?
a) attribute b) behavior c) state d) Both a and b
9. What are defined by variables in a class?
a) Behavior b) Attribute c) State d) methods
10. Which of the following is used to access or modify attributes?
a) Method b) class c) Attribute d) Behavior
11. What is defined by method in a class?
a) Method b) class c) Attribute d) Behavior
12. Write the right steps to create an object.
a) Declaration b) Instantiation c) Initialization. d) All of these
13. Declaring a variable does not create an …………. in Java.
a) Object b) method c) Attribute d) Behavior
14. Variable of class type are also referred to as …………. variables.
a) reference b) Global c) Allocated d) Constant
15. Which operator allocates the memory for an object and returns the address of
object?
a) new b) object c) class d) Method
16. What do we call the address of the memory location where the object is stored?
a) Address b) Reference c) Allocated d) Constant
17. What do we call the special portion of memory where the objects live?
a) Reference b) Heap c) Address d) Structure
18. When an object is created, then which special method is executed to perform
initial task?
a) Constructor b) Method c) Attributes d) Function
19. Which constructor is called with empty parentheses without arguments?
a) Object constructor b) default constructor
c) Method d) Parameterized constructor
20. When statement “r1=new Room( );” is executed then what is stored in r1?
a) Address of an object b) Reference of an object
c) Heap d) All of these
21. Which of the following is the correct syntax to declare and create an object in a
single line?
a) Room r2=new Room( ); b) room r=room();
c) Room r1=room() d) Room =Room(new);
22.In Java, which of the following looks for unused objects and reclaims the
memory that those objects are using?
a) Variable collector b) Garbage collector
c) Class collector d) Object collector
23.In Java, creating an object with „new‟ key word is also called object ……………..
a) Declaration b) Instantiation c) Initialization d) All of these
24. Which type of variables is created at the time of creating an object and
stay throughout the life of the ojects ?
a) Local b) Instance c) Static d) null
25.Which type of variable is define by the attributes of an object?
a) Local b) Instance c) Static d) null
26.In Java, …………. can be defined inside a class only.
a) method b) class c) Attributes d) State
27.All instance of class are allocated memory in which data structure?
a) heap b) constructor c) Inherit d) Overload
28. Write down the syntax of accessing and calling instance variable.
Ans. <object reference>.<<instance variable or method>
29.What is the associativity of dot operator?
a) L to R b) R to L c) T to B d) B to T
30. Instance variables and instance methods can be referred by using
………….operators.
a) dot ( . ) b) comma( „ ) c) semicolon( ; ) d) colon( : )
31. Referring instance variable or invoking method with null reference will give
…………
a) output b) Error c) Object d) Class
32.Instance methods are used to define ………… of an object.
a) Attribute b) Behavior c) state d) Functions
33. Variable belongs to a class and not to an …………
a) Attribute b) Object c) Behavior d) method
34. Which variables are called the class variable can be declared within class
using static keyword before data type ?
a) Memory b) static c) local d) instance
35.What do we call the variables that defined inside methods or blocks?
a) Local variable b) Class variable c) Static variable d) Instance variable
36. What do we call the variables that are defined within a class but outside
any method?
a) Instance variable b) Class variable c) Static variable d) Local variable
37.Which variables are initialized with default value?
a) Instance and class variable b) Class and local variables
c) class and static variable d) Static and Instance variable
38. What do we call the term where different forms of methods are used with
same name?
a) Polymorphism b) Inheritance c) constructor d) Aggregation
39.The word …………….. means many forms.
a) Polymorphism b) Inheritance c) constructor d) Aggregation
40. Which term means, different methods that have the same name but a
different signature?
a) Method overloading (b) Inheritance c) Constructor d) Aggregation
41. Which of the following are the steps to create Polymorphism?
a) Method name b) type of return value c) a list of parameters d) All of these
42. What do we call the special method that is invoked when a new object is
created?
a) Polymorphism b) Constructor c) Inheritance d) All of these
43. Every class is having its default ……………
a) Polymorphism b) Constructor c) Inheritance d) All of these
44. Which type of constructor does not take any argument?
a) Default b) Parameterized c) Multi level d) Multiple
45. Which is mainly designed to perform initializing actions?
a) Constructor b) Polymorphism c) Inheritance d) All of these
46. Constructor does not have ……………….. type.
a) return b) void( ) c) default d) All of these
47.Constructor is invoked implicitly only when an object is constructed using
………..operator.
a) new b) default c) new( ) d) +
48. Constructor must have the ………….. name as class name.
a) same b) new name c) different d) default
49.Which of the following is the correct for the Constructor?
i. Constructor must have the same name as class name.
ii. Constructor does not have return type.
iii. Constructor is invoked implicitly only when an object is constructed using
new operator.
iv. Constructor can not be invoked explicitly elsewhere in the program.
v. constructor can be invoked implicitly.
a) i, ii, iii, iv b) i, ii, v, iii c) v, i ,iv, iii d) v, i, iii,,iv
50. Access control means to control ……….
a) visibility b) program c) Objects d) Attributes
51. In absence of user define constructor in a class, objects are constructed using
which type of constructor?
a) Default b) no – argument c) Parameterized d) multilevel
52.Which of the following is the meaning of polymorphism?
a) Single form b) Post text c) Post morphism d) Many forms
53.What is known as visibility modifier?
a) Access modifier b) Constructor c) Polymorphism d) Inheritance
54. Which of the following is a part of Four P‟s Protection in Java?
a) Private b) Package, Protected c) Public d) All of these
55.Which of the following is not a part of Four P‟s protection in Java?
a) public b) package c) private d) provided
56. Which type of access modifiers are used before the type of variable or
method?
a) public b) protected c) private d) All of these
57.Which of the following access modifier is used to organized classes?
a) Public b) Package c) Private d) Protected
58. Which access modifier provides visibility to classes defined in the other
package? a) public b) package c) Private d) Protected
59.To provide public access, which keyword type before method or variable type?
a) Private b) Public c) Protected d) Package
60. Public variables and methods are …………… anywhere.
a) visible b) invisible c) outside d) inside
61. Which of the following is the highest level of protection in Java?
a) Private b) Package c) Public d) Protected
62.What is the other name of mutator method?
a) set b) setter c) getter d) get
63. What is the other name for accessor method.
a) get b) getter c) setter d) set
64. Which level of protection is used to allow the access only to subclasses or
to share with the methods declared as “friend”?
a) public b) protected c) Private d) Package
65. Which keyword is used to share data of private class?
a) friend b) extends c) throw d) get
Chapter -8 Classes and Objects in Java
6
66. Which protection level cannot be seen by any other class?
a) Private b) Protected c) Public d) Package
67.If we want private data to be used by other, then which method is used?
a) accessor b) access c) excess d) mutator
68. If we want to allow private data to be modified by others, then which
method is used?
a) accessor b) access c) excess d) mutator
69.Which of the following prefix is utilize for conventionally naming of mutator
method?
a) wait b) set c) get d) take
70.Which of the following prefix is utilize for conventionally naming of accessor
method?
a) wait b) set c) get d) take
71. If we want to allow other methods to read only the data value, then which
method is used?
a) getter b) get c) set d) setter
72.If we want to allow other methods to modify the data value, then which method
is used?
a) getter b) get c) set d) setter
73.Find the valid getter or setter names from the list.
(1) getLength (2) GetLength (3) getlength (4) setLength (5)SetLength (6)
setAttribute
a) 1,3,4,6 b) 1,4,6 c) 1,2,3,4 d) 1,3,4,6
74.Which facility allows us to build new class with added capabilities by extending
existing class?
a) Inheritance b) Constructor c) Polymorphism d) Aggregation
75.Inheritance model is based on which type of relationship between two classes?
a) has – a – part b) is – a – kind c) is-a-kind-of d) both b or c
76.In inheritance, Parent class is also referred to as …………. class.
a) super b) base c) sub d) both a and b
77. In inheritance, Child class is also referred to as ………….. class.
a) sub b) derived c) extended d) All of these
78.In which class common features are kept?
a) super b) extended c) sub d) None of above
79.Which class inherits all instance variables and methods from super class, and it
may have its own added variables and methods?
a) Base class (b) Subclass c) Sub class d) None of above
80. What is not inherited in sub class?
a) Constructor b) Method c) Polymorphism d) Super class
81. Which keyword is used to create a subclass in the class definition?
a) derived b) extends c) Super d) new
82. Which keyword is used to call the constructor of super class in the
constructor of sub class?
a) extends b) super c) extends d) new
83. When super class and sub class have methods with same signature, a
super class method is said to
be ……………. in the sub class.
a) overloading b) overridden c) operator loading d) None of above
84. All instance variable and methods are inherited from super class to
…………..class.
a) sub b) Parent c) super d) new
85. Java does not support …………….type of inheritances.
a) multiple b) Single c) multi level d) constructor
86. A subclass can be derived from only the ……………. class.
a) Super b) new c) Extended d) sub
87.Which of the following are the construction of classes that incorporate other
objects. They establish
a “has-a” relationship between classes?
a) Composition b) aggregation c) Constructor d) Both a or b
88. Composition & aggregation establish which type of relationship between
classes?
a) has – a – part b) has – a c) is-a-kind-of d) Both a or b
89.Which symbol is used in Inheritance?
a) Arrow b) Circle c) Diamond d) Triangle