Inheritance in x++
What is Inheritance in x++?
answer:
Inheritance is a concept where child class (derived class) can inherit all the methods and variables. from parent class(base class).
Rules:
-> A class can extend only one other class.
-> Multiple inheritance isn't supported.
-> If we extend a class, the subclass (derived class) inherits all the methods and variables in the parent class (the superclass).
-> Subclasses let us reuse existing code for a more specific purpose.
-> A superclass is often known as a base class, and a subclass is often known as a derived class.
How to prevent the inheritance?
ans:
We can prevent classes from being inherited by using the final modifier.
Example:
public final class Attribute
{
int objectField;
}
Comments
Post a Comment