Skip to content

Added details about constructors and methods #443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions OOPs/inheritance.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,20 @@ class Science extends Faculty {

Salary is:30000.0
Bonous is:2000.0

### Facts About Constructors in Inheritance
A sub class constructor is used to initialise the instance variables of both the subclass and super class. The sub class constructor invokes the super class constructor either implicitly or by using the keyword super.

1). super() — invoking the non-parameterized constructor of super class.

2). super(parameters_list) — invoking the parametrized constructor of super class.

### Note:
1). If the super class definition contains a parametrized constructor then the sub class constructor must have a parametrized constructor explicitly invoking a super(…).

2). Explicit invocation of a super class constructor must be the first line of sub class constructor.

### Method Overriding
A concept which occurs when an instance method in a sub class hides method of the super class due to similar declarations. An over-ridden super class method can be invoked using the super keyword.
>Syntax:
super.overridenMethod()