05. Inheritance Questions

What is Inheritance?

Inheritance is a mechanism in which one object acquires all the properties and behaviour of another object of another class. It represents IS-A relationship. It is used for Code Resusability and Method Overriding.

Which class is the superclass for every class.

Object class

Why multiple inheritance is not supported in java?
  • To reduce the complexity and simplify the language, multiple inheritance is not supported in java in case of class.


What is composition?

Holding the reference of the other class within some other class is known as composition


What is difference between aggregation and composition?

Aggregation represents weak relationship whereas composition represents strong relationship. For example: bike has an indicator (aggregation) but bike has an engine (compostion)


Why Java does not support pointers?

Pointer is a variable that refers to the memory address. They are not used in java because they are unsafe(unsecured) and complex to understand


What is super in java?

It is a keyword that refers to the immediate parent class object


Can you use this() and super() both in a constructor?

No. Because super() or this() must be the first statement


What is object cloning?

The object cloning is used to create the exact copy of an object.


No comments:

Post a Comment