Std12e ch8

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Chapter -8

Classes and Objects in Java


-------------------------------------------------------------------------------------------------------------

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

1
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>
2
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

3
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

46. Constructor is invoked implicitly only when an object is constructed using


………..operator.
a) new b) default c) new( ) d) +

47. Constructor must have the …………..name as class name.


a) same b) new name c) different d) default

48. 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

49. Access control means to control ……….


a) visibility b) program c) Objects d) Attributes

50. 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

51. Which of the following is known as a user-defined no-argument constructor?


a) <classname> { } [ ]; b) <classname> ( ) {};
c) <classname> ( ) [ ]; d) <classname> [ ] ( );

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
4
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. Write down the syntax of package.


Ans. package <packageName>;

59. Which access modifier provides visibility to classes defined in the other package?
a) public b) package c) Private d) Protected

60. To provide public access, which keyword type before method or variable type?
a) Private b) Public c) Protected d) Package

61. Public variables and methods are …………..anywhere.


a) visible b) invisible c) outside d) inside

62. Which of the following is the highest level of protection in Java?


a) Private b) Package c) Public d) Protected

63. What is the other name of mutator method?


a) set b) setter c) getter d) get

64. What is the other name for accessor method.


a) get b) getter c) setter d) set

65. Match the correct access modifier with its visibility.


Access modifier Visibility
1 public A →→→
2 Default: package B narrowest
3 protected C widest
4 private D →→

a) (1-C, 2-A,3-D, 4-B) b) (1-C, 2-D, 3-A, 4-B)

66. 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

67. Which keyword is used to share data of private class?


a) friend b) extends c) throw d) get

68. Which protection level cannot be seen by any other class?


a) Private b) Protected c) Public d) Package

5
69. If we want private data to be used by other, then which method is used?
a) accessor b) access c) excess d) mutator

70. 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

71. Which of the following prefix is utilize for conventionally naming of mutator
method?
a) wait b) set c) get d) take

72. Which of the following prefix is utilize for conventionally naming of accessor
method?
a) wait b) set c) get d) take

73. 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

74. 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

75. 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

76. Which facility allows us to build new class with added capabilities by extending
existing class?
a) Inheritance b) Constructor c) Polymorphism d) Aggregation

77. 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

78. In inheritance, Parent class is also referred to as………….class.


a) super b) base c) sub d) both a and b

79. In inheritance, Child class is also referred to as …………..class.


a) sub b) derived c) extended d) All of these

80. In which class common features are kept?


a) super b) extended c) sub d) None of above

81. 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

6
82. What is not inherited in sub class?
a) Constructor b) Method c) Polymorphism d) Super class

83. Which keyword is used to create a subclass in the class definition?


a) derived b) extends c) Super d) new

84. 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

85. 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

86. All instance variable and methods are inherited from super class to
…………..class.
a) sub b) Parent c) super d) new

87. Java does not support …………….type of inheritances.


a) multiple b) Single c) multi level d) constructor

88. A subclass can be derived from only the …………..class.


a) Super b) new c) Extended d) sub

89. 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

90. 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

91. Which symbol is used in Inheritance?


a) Arrow  b) Circle c) Diamond d) Triangle

Textbook Exercise

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 (=)

7
4. Which method can be called without creating an instance of a class?
a) Instance method b) Class Method c) Constructor method d) All of the above

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

6. Which method is invoked automatically with creation of an object?


a) Instance method b) Constructor c) class method d) All of the above

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 instance variables and class variables d) Constructor

10. When method in the superclass and subclass have same name and signature,
what are they called?
a) Overloaded methods b) Inherited methods
c) Inherited methods d) All of the above.

You might also like