Skip to content
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

Update java.md #461

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
59 changes: 59 additions & 0 deletions java.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,62 @@ public class AA { //beg of class
}
}
```

### this Keyword

this keyword is used to refer to the current instance of an object.
It can be used to access instance variables, if both local variables and instance variables have the same name.

```java
public class Student {
private String stuName, address, rollNumber;
Student (String stuName, String address, String rollNumber) {
this.stuName = stuName;
this.address = address;
this.rollNumber = rollNumber;
}
}
```

### Final Keyword

final is a keyword and access modifier for restricting access to a class, method, or variable

* A final variable's value once initialized can't be changed
```java
final int value = 0;
```

* A final method cannot be overridden in a subclass
```java
final int calculateValue(){
return 0;
}
```

* A final class cannot be subclassed. (i.e. you cannot extend the class)
```java
public final class ValueCalc {
int num = 0;
int calcNum(){
return 0;
}
}
```

### Super Keyword

* Super is used to invoke parent class constructor
```java
super();
```

* It is used to access instance variable of parent class
```java
super.variableNameOfParent;
```
* It is used to access methods of parent class
```java
super.parentMethod();
```