Skip to content

Commit 1b0e55f

Browse files
authored
added my code
1 parent f3bf945 commit 1b0e55f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

java_inheritance_code/vss240.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Terms used in Inheritance
2+
- Class: A class is a group of objects which have common properties. It is a template or blueprint from which objects are created.
3+
Sub Class/Child Class: Subclass is a class which inherits the other class. It is also called a derived class, extended class, or child class.
4+
Super Class/Parent Class: Superclass is the class from where a subclass inherits the features. It is also called a base class or a parent class.
5+
Reusability: As the name specifies, reusability is a mechanism which facilitates you to reuse the fields and methods of the existing class when you create a new class. You can use the same fields and methods already defined in the previous class.
6+
# The syntax of Java Inheritance
7+
class Subclass-name extends Superclass-name
8+
{
9+
//methods and fields
10+
}
11+
The extends keyword indicates that you are making a new class that derives from an existing class. The meaning of "extends" is to increase the functionality.
12+
13+
# In the terminology of Java, a class which is inherited is called a parent or superclass, and the new class is called child or subclass.
14+
Java Inheritance Example
15+
# Inheritance in Java
16+
- As displayed in the above figure, Programmer is the subclass and Employee is the superclass. The relationship between the two classes is Programmer IS-A Employee. It means that Programmer is a type of Employee.
17+
class Employee{
18+
float salary=40000;
19+
}
20+
class Programmer extends Employee{
21+
int bonus=10000;
22+
public static void main(String args[]){
23+
Programmer p=new Programmer();
24+
System.out.println("Programmer salary is:"+p.salary);
25+
System.out.println("Bonus of Programmer is:"+p.bonus);
26+
27+
28+
![image](https://user-images.githubusercontent.com/100853056/193450818-6d6e463e-696a-407c-ad85-a3a9d120e38c.png)
29+
30+
}
31+
}

0 commit comments

Comments
 (0)