1.what is inheritance?
- inheritance is one of the oops concepts in java.inheritance is concept of getting properties of one class object to another class object.
- Inheritance represents the IS-A relationship,also known as parent-child relationship.
1.Multiple inheritance( java doesn't support multiple inheritance).
2.Multilevel inheritance.
3.How Inheritance can be implemented in java?
- Inheritance can be implemented in JAVA using below two keywords:
2.implements
- extends is used for developing inheritance between two classes and two interfaces.
- implements keyword is used to developed inheritance between interface and class.
1.For Code Re usability.
2.For Method Overriding.
5.what is syntax of inheritance?
public class subclass extends superclass{
//all methods and variables declare here
}
6.what is multilevel inheritance?
- Getting the properties from one class object to another class object level wise with different priorities.
6.what is Multiple inheritance?why Java Doesn't Support multiple Inheritance.
- The concept of Getting the properties from multiple class objects to sub class object with same priorities is known as multiple inheritance.
- In multiple inheritance there is every chance of multiple properties of multiple objects with the same name available to the sub class object with same priorities leads for the ambiguity. also known as diamond problem. one class extending two super classes.
- Because of multiple inheritance there is chance of the root object getting created more than once.
- Always the root object i.e object of object class hast to be created only once.
- Because of above mentioned reasons multiple inheritance would not be supported by java.
- Thus in java a class can not extend more than one class simultaneously. At most a class can extend only one class.
8.How do you implement multiple inheritance in java?
- Using interfaces java can support multiple inheritance concept in java. in java can not extend more than one classes, but a class can implement more than one interfaces.
interface A{
}
interface B{
}
class C implements A,B{
}
9.Can a class extend itself?
- No,A class can't extend itself.
10.What happens if super class and sub class having same field name?
- Super class field will be hidden in the sub class. You can access hidden super class field in sub class using super keyword.
11.Inheritance definition and basic interview programs
12.Inheritance programming interview questions for freshers and experienced
13.Can we call sub class methods using super class object
14.Can we overload static methods in java
15.Can we override static methods in java
16.Can we override private method in java
12.Inheritance programming interview questions for freshers and experienced
13.Can we call sub class methods using super class object
14.Can we overload static methods in java
15.Can we override static methods in java
16.Can we override private method in java
is child class is used for parent class in any cases.If not used Why?
ReplyDeleteNice Article
ReplyDeletegood stuff to prepare thanks
ReplyDelete