[go: up one dir, main page]

0% found this document useful (0 votes)
9 views12 pages

Assignment 3

The document contains a series of multiple-choice questions related to Java programming concepts, specifically focusing on inheritance, access modifiers, and polymorphism. It includes questions about keywords, class structures, and the principles of object-oriented programming. Additionally, there are essay questions that require the creation of a parent class and its subclasses demonstrating the use of inheritance and polymorphism.

Uploaded by

salmaibraheemali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views12 pages

Assignment 3

The document contains a series of multiple-choice questions related to Java programming concepts, specifically focusing on inheritance, access modifiers, and polymorphism. It includes questions about keywords, class structures, and the principles of object-oriented programming. Additionally, there are essay questions that require the creation of a parent class and its subclasses demonstrating the use of inheritance and polymorphism.

Uploaded by

salmaibraheemali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Assignment 3

1_ Which member of the superclass is never accessible to the subclass.


a) Public member
b) Protected member
c) Private member
d) All of the mentioned
Answer: c) Private member

2_ keyword in Java which is used as a reference to the object of the current class,
with in an instance method or a constructor.
a) Super
b) New
c) This
d) Private
Answer: c) This

3_ keyword Is used to differentiate the instance variables from local variables if


they have same names, within a constructor or a method.
a) Super
b) New
c) This
d) Private
Answer: c) This
4_ A class, method, constructor, interface, etc. declared …..can be accessed from
any other class.
a) Public access modifier
b) Private access modifier
c) Default access modifier
d) None of the above
Answer: a) Public access modifier

5_ can be defined as the process where one class acquires the properties (methods
and fields) of another.
a) Polymorphism
b) Encapsulation
c) Inheritance
d) Interfaces
Answer: c) Inheritance

6_ is the keyword used to inherit the properties of a class.


a) Super
b) Inherits
c) Override
d) Extends
Answer: d) Extends
7_ When there may be two or more possible matches for an invocation of a
method, but the compiler cannot determine the most specific match this is
called…..
a) Recursion
b) Overriding
c) Overloading
d) Ambiguous calling
Answer: d) Ambiguous calling

8_ A subclass inherits all the members from its superclass except……..


a) Objects
b) Getters
c) Setters
d) Constructors
Answer: d) Constructors

9_ is used to invoke the superclass constructor from subclass.


a) Super
b) This
c) New
d) Superclass
Answer: a) Super
10_ Which of the following allows the creation of hierarchical classifications?
a) Interface
b) Inheritance
c) Package
d) Polymorphism
Answer: b) Inheritance

11_ Which of the following keywords is used to prevent inheritance?


a) final
b) catch
c) extends
d) super
Answer: a) final

12_ is used as a base class to derive specific classes of the same kind.
a) private
b) friend class
c) abstract class
d) super class
Answer: c) abstract class

13_ Applying abstraction means focusing only on the important characteristics of


the entity to be abstracted.
a) True
b) False
Answer: a) True
14_ A superclass’s ---------- members can be accessed in the superclass declaration
and in subclass declarations.
a) private
b) protected
c) public
d) private & protected
Answer: b) protected

15_ Subclass constructors can call superclass constructors via---------- the keyword.
a) subclass
b) superclass
c) super
d) Sub
Answer: c) super

16_ Method overriding is combination of inheritance and polymorphism.


a) True
b) False
Answer: a) True

17_ Superclass constructors are not inherited by subclasses.


a) True
b) False
Answer: a) True
18_ Inheritance encourages the reuse of proven high-quality software.
a) True
b) False
Answer: a) True

19_ A superclass’s…….. members are accessible anywhere that the program has a
reference to an object of that superclass or to an object of one of its subclasses.
a) public
b) private
c) void
d) none
Answer: a) public

20_ When an object of a subclass is instantiated, a superclass……. is called


implicitly or explicitly.
a) final variable
b) setters methods
c) constructor
d) accessor methods
Answer: c) constructor

21_ When a subclass redefines a superclass method by using the same signature,
the subclass is said to overload that superclass method.
a) True
b) False
Answer: b) False
22_ Which of the following functions can be inherited from the base class ?
a) constructor
b) destructor
c) static
d) None of the above
Answer: d) None of the above

23_ The access specifier that is/are the most secure during inheritance is/are
a) Protected
b) Private
c) Private and Default
d) Default
Answer: b) Private

24_ A derived class is also called a..........................


a) Small class
b) Subclass
c) Access modifier
d) Method signature
Answer: b) Subclass

25_ is a process of hiding the implementation details and showing only


functionality to the user.
a) inheritance
b) abstraction
c) overloading
d) overriding
Answer: d) overriding
abstraction
26_ …... is implicitly abstract.
a) object
b) class
c) interface
d) All of these
Answer: c) interface

27_ There are two ways to achieve abstraction in java which are..........
a) Object, class
b) Inheritance, overriding
c) Inheritance, abstract class
d) Interfaces, abstract class
Answer: d) Interfaces, abstract class

28_ A subclass redefines a superclass method by using the same signature, this is
called….
a) Ambiguous calling
b) overloading
c) overriding
d) inheritance
Answer: c) overriding

29_ A class can implement………… interface at a time.


a) Only one
b) Maximum two
c) More than one
d) None of the above
Answer: c) More than one
30_ A class can extend ……class.
a) Only one
b) More than two
c) More than one
d) None of the above
Answer: c) More than one

31_ An abstract class can contain non abstract methods.


a) True
b) False
Answer: a) True
Essay Question
Using the concept of inheritance and polymorphism in object oriented
A_ Create a parent class called Animal , specify a method called sound that prints
“Animal able to make a sound”
Answer:
B_ Inherits 4 subclasses (child classes) with names: “Dogclass, bearclass,
duckclass,and snakeclass” from the base class Animal, override the sound method
of the base class in each sub class to be “woof”, “Growll”, “Quackkk”, “ Hisss”.
Answer:
C_ Apply the polymorphism concept and call the sound method of each sub class
and display output.
Answer:

You might also like