Professional Documents
Culture Documents
Ans:
To access the member of different class user may use Aggregation or
Inheritance.
Ans:
Aggregation is use to access the member of another class.
Ans:
To access the resource of super class inside the child class without creating
object of each individual class is Inheritance.
Ans:
Use of Inheritance is:
i) To use Polymorphism.
ii) To promote code reuse.
5. Types of inheritance?
Ans:
Inheritance is of 5 types. They are:
i) Single Inheritance
ii) Multilevel Inheritance
iii) Hierarchical Inheritance
iv) Hybrid Inheritance
v) Multiple Inheritance.
Ans:
Class never support Multiple Inheritance because it create ambiguity of members.
Ans:
When a class has more than one Super class is known as Multiple Inheritance.
Ans:
All the methods of interface are public and abstract and user has to override within the
sub class. Sub – class object always search the member within the sub –class first , and
if member not present in sub class then it will search in super class. But in case of
interface all the methods has to override in sub class before instantiating. So it never
creates any ambiguity.
Ans:
Major problem of Aggregation is user want to create object of each individual class for
accessing the resource which is not possible each and every time in Aggregation.
Ans:
Yes. When object create in the child class it create the object of all the super class.
11. Is there any other way that you can achieve inheritance in Java?
Ans:
Please create an anonymous class of type implement parent interface, kindly override
the method parent method ().
Ans:
When object create in the child class it create the object of all the super class.
13. I don't want my class to be inherited by any other class. What should i do?
Ans:
I have to declare the class as Final.
Ans:
Two keyword s has special use in Inheritance. They are:
i) Extend
ii) Implements…….
15. State the name of the class which is inherited and which is not inherited?
Ans:
The class which is inherited is known as Super class and the class which is not inherited
is known as Sub class.
Ans:
A more than one class belongs to a single class is Hierachical Inheritance.
Ans:
Extends keyword indicates that you are making a new class that derives from an
existing class.
Ans:
Aggregation represent HAS-A and IS-A relationship.
Ans:
Inheritance should be used only if the relationship IS-A is maintained throughout the
lifetime of the objects involved otherwise Aggregation is the best choice .
Ans:
Object class.
Ans:
Yes.
Ans:
Java.lang.Object is the base class of all the classes.
24. Can you give few examples of final classes defined in Java API?
Ans:
All the Wrapper classes including String, StringBuffered are the example of final class in
java API.
Ans:
To access the member of Default class user usegetClass () method and getSuperClass ()
method.
Ans:
Object is the parent class of all the class in java directly or indirectly.
27. What is the problem of aggregation?
Ans:
Major problem of Aggregation is user want to create object of each individual class for
accessing the resource which is not possible each and every time in Aggregation.