Std 12 Computer Chapter 8 Classes and Objects in Java important MCQs
Std 12 Computer MCQs
Computer std 12 mcq ch 8
computer std 12 ch 8 mcq
std 12 important mcq
chapter 8 Classes and Object in Java
creating a class in java
creating an object in java
constructor in java
inheritance in java
polymorphism in java
method overloading and method overridden
2. Compiled by Nuzhat Memon
2
1. What do you mean by class?
a) Data & program code
b) Data & method
c) Only data
d) Only program code
2. Which of the following is the correct syntax for defining a
class ?
a) class [class name] { <variable><methods>}
b) class <class name> {<variable> <methods>}
c) class {class name} ( <variable> <methods> )
d) class (class name) { <variable> <method> }
3. Compiled by Nuzhat Memon
3
3. In class, Data is referred to as____________
a) attributes
b) behavior
c) state
d) None of these
4. In Java, functions referred to as __________
a) attributes
b) behavior
c) state
d) None of these
4. Compiled by Nuzhat Memon
4
5. In Java, by which component is the class generally
made up of?
a) Name, variable
b) Behaviour , variable
c) Name, attributes
d) Attributes, behaviour
6. In java, which of the following defines attributes and
methods?
a) Class
b) Object
c) Instance
d) Variable
5. Compiled by Nuzhat Memon
5
7. ___________ is a template for multiple objects with
similar features.
a) Public
b) Main
c) Static
d) Class
8. In Java, a class is defined using which keyword ?
a) public
b) main
c) static
d) class
6. 6
9. What are defined by variables in a class ?
a) Attribute
b) Behaviour
c) State
d) Methods
10. What are defined by method in a class?
a) Class
b) State
c) Attribute
d) Behaviour
7. 7
11. Which of the following is used to access or modify
attributes?
a) Class
b) State
c) Attribute
d) Method
12. Variables belongs to a class and not to an ......
a) Object
b) Attribute
c) Behaviour
d) Method
8. Compiled by Nuzhat Memon
8
13. In Java, which operator allocates the memory
for an object and returns the address of object?
a) add
b) class
c) super
d) new
14. What is the name of the data structure, where
all instances of class are allocated memory?
a) reference
b) heap
c) class
d) variable
9. Compiled by Nuzhat Memon
9
15. Variable of class type are also referred to as
_______variables.
a) Global
b) Reference
c) Allocated
d) Constant
16.What do we call the address of the memory
location where the object is stored?
a) Reference
b) Address
c) Allocated
d) Constant
10. Compiled by Nuzhat Memon
10
17. Which steps are required to create an object from a
class in java?
a) declaration
b) instantiation
c) initialization
d) all of these
18. In object oriented programming (OOP) language,
creating an object is also known as what?
a) object instantiation
b) object creating
c) object making
d) none of these
11. Compiled by Nuzhat Memon
11
19.In Java, which step of creating an object from a
class initialize the newly created object ?
a) Declaration
b) Instantiation
c) Initialization
d) All of these
20. Java have a ..... that looks for unused objects and
reclaims the memory that those objects are using.
a) Unused collector
b) Garbage collector
c) Reclaim collector
d) Memory collector
12. Compiled by Nuzhat Memon
12
21. In Java class, in which step a ‘new’ keyword is used
to create the object by allocating memory?
a) Declaration
b) Instantiation
c) Initialization
d) All of these
22. ____________ is special kind of method called to
initialize the newly created object.
a) classes
b) reference variable
c) syntax variable
d) constructor
13. Compiled by Nuzhat Memon
13
23. A variable declared using class type can only store
what?
a) store an object
b) reference to an object
c) classified an object
d) interfere an object
24. In java, Which of the following is not a step of
creating an object from a class?
a) Declaration
b) Instantiation
c) Initialization
d) Calculation
14. Compiled by Nuzhat Memon
14
25. 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 r1=room()
c) Room r=room();
d) Room = Room(new);
26. When statement “r1= new Room( );” is executed
then what is stored in r1?
a) Heap
b) Address of an object
c) Reference of an object
d) All of these
15. Compiled by Nuzhat Memon
15
27. Declaring a variable does not create an ______ in
java.
a) Method
b) Attribute
c) Behaviour
d) Object
28. When a program contains 2 or more classes, only
one class can contain the _____________ method
a) private
b) class
c) string()
d) main()
16. Compiled by Nuzhat Memon
16
29. Which of the following represents the type of variable ?
a) Instance variables
b) Local variables
c) Class variables
d) All of these
30. Variables defined inside methods or blocks are known as
which type of variable ?
a) Local variables
b) Block variables
c) Instance variables
d) Class variables
17. Compiled by Nuzhat Memon
17
31. Which type of variables is created at the time
of creating an object and stay throughout the life
of the objects?
a) Local
b) Instance
c) Static
d) Null
32. Which type of variable is define by the
attributes of an object?
a) Local
b) Instance
c) Static
d) Null
18. Compiled by Nuzhat Memon
18
33. Which is the correct syntax of accessing and calling instance
variable?
a) <object reference>.<instance variable or method>
b) <instance variable or method>.<object reference>
c) (object reference).(instance variable or method)
d) None of these
34. 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 class, colon(:) and the name of the method.
c) The name of the object, dot(.) and the name of the method.
d) The name of the class, dot(.) and the name of the method.
19. Compiled by Nuzhat Memon
19
35. From which of the following operators can we access
instance variables and instance methods ?
a) . ( dot)
b) : ( colon)
c) , ( comma)
d) ; ( semi colon)
36. What is the associativity of . (dot) operator which is
used to access instance variable ?
a) Upper to Lower
b) Right to Left
c) Lower to Upper
d) Left to Right
20. Compiled by Nuzhat Memon
20
37. Which type of variables are defined within a class but
outside any method?
a) Class variables
b) Block variables
c) Instance variables
d) Local variables
38. Which type of variables are defined within a class but
outside any method with static keyword?
a) Class variables
b) Block variables
c) Instance variables
d) Local variables
21. Compiled by Nuzhat Memon
21
39. Referring instance variable or invoking method with
null reference will give _____
a) Output
b) Object
c) Class
d) Error
40. Which variables are initialized with default value?
a) class and local variables
b) Instance and class variable
c) class and static variable
d) local and instance variable
22. Compiled by Nuzhat Memon
22
41. ________ are created when the method or block is
started and destroyed when the method or block has
completed.
a) Instance variable
b) Class variable
c) Local variable
d) None of these
42. 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
23. Compiled by Nuzhat Memon
23
43. How do you identify the variable which is define with
in a class, out-side any method with the static key word
in Java ?
a) Block variables
b) Local variables
c) Instance variables
d) Class variables
44. Which of the following keyword is used to declare
Class variables and class methods ?
a) private
b) static
c) package
d) public
24. Compiled by Nuzhat Memon
24
45. Which of the following is accessible by instance methods ?
a) Only class variables
b) Only instance variables
c) Both instance variables and class variables
d) Constructor
46. Which of the following is accessible by class methods ?
a) Only class variables
b) Only instance variables
c) Both instance variables and class variables
d) Constructor
25. Compiled by Nuzhat Memon
25
47. Constructor is invoked implicitly only when an object is
constructed using ______ operator
a) default
b) new
c) new()
d) +
48. Constructor must have the _____ name as class name.
a) New
b) Same
c) Different
d) Default
26. Compiled by Nuzhat Memon
26
49. In Java, which method is invoked automatically with
creation of an object ?
a) Instance method
b) Class method
c) Constructor
d) None of these
50. Which of the following can perform any action, but it is
mainly designed to perform initializing actions ?
a) Consolidation
b) Constructors
c) Confirmation
d) Contractor
27. Compiled by Nuzhat Memon
27
51. Which constructor is called with empty
parenthesis without arguments ?
a) Default constructor
b) Object constructor
c) Method
d) Parameterized constructor
52. Every class is having its default .........................
a) Inheritance
b) Constructor
c) Polymorphism
d) All of these
28. Compiled by Nuzhat Memon
28
53. In absence of user define constructor in a class, objects
are constructed using which type of constructor ?
a) No – argument
b) Parameterized
c) Multi level
d) Default
54. Which of the following is known as a user – defined no –
argument constructor ?
a) <classname> () {};
b) <classname> () [ ];
c) <classname> () [ ];
d) <classname> [ ] ();
29. Compiled by Nuzhat Memon
29
54. Which type of constructor does not take any argument ?
a) Default
b) Multiple
c) Multi level
d) Parameterized
55. Constructor does not have _______ type.
a) void()
b) Return
c) Default
d) All of these
30. Compiled by Nuzhat Memon
30
56. 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, v, iii
b) i, ii, iii, iv
c) v, i, iv, iii
d) v, i, iii, iv
31. Compiled by Nuzhat Memon
31
57. Which word means “many forms”, different forms of
method with same name in Java?
a) Aggregation
b) Polymorphism
c) Composition
d) None of these
58. 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
32. Compiled by Nuzhat Memon
32
59. In java, we can have different methods that have the
same name but a different signature is also called as what ?
a) overloading method
b) Overridden method
c) overloading class
d) Overridden signature
60.When methods in superclass and subclass have same name
and signature, what are they called?
a) Overloaded methods
b) overridden methods
c) Inherited methods
d) All of the above
33. Compiled by Nuzhat Memon
33
61. What is known as visibility modifier ?
a) Constructor
b) Inheritance
c) Polymorphism
d) Access modifier
62. Access control means to control ...........
a) Visibility
b) Objects
c) Program
d) Attributes
34. Compiled by Nuzhat Memon
34
63. In Java, how many levels of visibility modifiers are
available for access control ?
a) 5
b) 3
c) 4
d) 2
64. Which are the for P’s used in the four levels of visibility to
provide necessary protection ?
a) Process, Private, Protected, Public
b) Public, Package, Protected, Process
c) Public, Package, Protected, Private
d) Private, Package, Protected, Public
35. Compiled by Nuzhat Memon
35
65. Match the correct access modifier with its visibility
a) 1- C, 2- A, 3- B, 4- D
b) 1- C, 2- A, 3- D, 4- B
Access modifier Visibility
1 Public A
2 Default: Package B Narrowest
3 Protected C Widest
4 private D
36. Compiled by Nuzhat Memon
36
66. Which is the default level of protection, where lack of
any access modifier keyword is in a declaration in Java
a) Private
b) Package
c) Public
d) Protected
67. Which of the following is syntax of package ?
a) Package {Package Name};
b) Package <Package Name>;
c) Package (Package Name);
d) Package [Package Name];
37. Compiled by Nuzhat Memon
37
68. Which of the following access modifier is used to
organized classes ?
a) Public
b) Package
c) Private
d) Protected
69. Which access modifier provides visibility to classes
defined in the other package ?
a) Package
b) Public
c) Private
d) Protected
38. Compiled by Nuzhat Memon
38
70. To provide public access, which keyword type before
method or variable type?
a) Private
b) Public
c) Protected
d) Package
71. Public variables and methods are _______anywhere.
a) Invisible
b) Visible
c) Outside
d) Inside
39. Compiled by Nuzhat Memon
39
72. If we want to make visible to all the classes outside the
class, where method or variable is visible to class,
which type of access modifier is used ?
a) Public
b) Package
c) Protected
d) Private
73. Highest level of protection can be achieved by using
which protection level?
a) Protected
b) Package
c) Public
d) Private
40. Compiled by Nuzhat Memon
40
74. __________ members are available as ‘private’
members in the inherited subclass.
a) Public
b) Package
c) Protected
d) Private
75. ____________ provides data encapsulation.
a) Protected
b) Package
c) Public
d) Private
41. Compiled by Nuzhat Memon
41
76. Accessor method is known as what in Java ?
a) set
b) setter
c) getter
d) get
77. Mutator method is known as what in Java ?
a) setter
b) set
c) get
d) getter
42. Compiled by Nuzhat Memon
42
78. If we want to allow other methods to read only the data
value, then which method is used ?
a) writer
b) reader
c) Getter
d) Setter
79. If we want to allow other methods to modify the data
value, then which method is used ?
a) write
b) getter
c) reader
d) Setter
43. Compiled by Nuzhat Memon
43
80. In Java, if we want to allow protect data to be used by
others, then which methods are to be written ?
a) Get
b) Mutator
c) Accessor
d) Set
81. In Java, if we want to allow protect data to be modified
by others, then which methods are to be written ?
a) Set
b) Get
c) Mutator
d) Accessor
44. Compiled by Nuzhat Memon
44
82. Which level of protection is used to allow the access only
to sub classes or to share with the methods declared as
“friend” in Java ?
a) Package
b) Private
c) Public
d) Protected
83.Which keyword is used to share data of private class?
a) Extends
b) Friend
c) Throw
d) Get
45. Compiled by Nuzhat Memon
45
84. Which of the following allows us to build new class with
added capabilities by extending existing class ?
a) Polymorphism
b) Composition
c) Aggregation
d) Inheritance
85. Inheritance establish which type of relationship
between two classes in java ?
a) is – a
b) has – a
c) have – a
d) are – a
46. Compiled by Nuzhat Memon
46
86. 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
87. In Java, which keyword is used to call the constructor
of super class in the constructor of sub class ?
a) class
b) extends
c) super
d) sub
47. Compiled by Nuzhat Memon
47
88. Which keyword is used to create a subclass in the class
definition?
a) class
b) extends
c) super
d) Sub
89. What is not inherited in sub class?
a) Constructor
b) Method
c) Polymorphism
d) Super class
48. Compiled by Nuzhat Memon
48
90. In Java, Parent class can be referred to as which of
the following ?
a) Sub class, Base class, Super class
b) Parent class, Super class, Base class
c) Sub class, Derived class, Extended class
d) Parent class, Extended class, Base class
91. In Java, Child class can be referred to as which of
the following ?
a) Parent class, Extended class, Base class
b) Sub class, Base class, Super class
c) Parent class, Super class, Base class
d) Sub class, Derived class, Extended class
49. Compiled by Nuzhat Memon
49
92. In inheritance, Parent class is also referred to as ____class.
a) Super
b) Sub
c) Base
d) Both a and c
93. In Java, a Sub class can be derived from which class ? OR
In Java, a Sub class inherits all instance variables and methods
from which class ?
a) Child class
b) Owner class
c) Extended class
d) Super class
50. Compiled by Nuzhat Memon
50
94. In which class common features are kept?
a) Super class
b) Extended class
c) Sub class
d) Derived class
95. 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) Sub class
c) Super class
d) Parent class
51. Compiled by Nuzhat Memon
51
96. Which symbol is used in Inheritance ?
a) Triangle
b) Diamond
c) Circle
d) arrow
97. Java does not support ......... type of inheritance .
a) Single
b) Multiple
c) Multi level
d) Constructor
52. Compiled by Nuzhat Memon
52
98. Composition and Aggregation establish which type of
relationship between classes in Java ?
a) As – a
b) Has – a
c) Is – a
d) Was – a
99. Composition and 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