 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The extends Keyword in Java
An object can acquire the properties and behaviour of another object using Inheritance. In Java, the extends keyword is used to indicate that a new class is derived from the base class using inheritance. So basically, extends keyword is used to extend the functionality of the class.
A program that demonstrates the extends keyword in Java is given as follows:
Example
class A {    int a = 9; } class B extends A {    int b = 4; } public class Demo {    public static void main(String args[]) {       B obj = new B();       System.out.println("Value of a is: " + obj.a);       System.out.println("Value of b is: " + obj.b);    } }  Output
Value of a is: 9 Value of b is: 4
Now let us understand the above program.
The class A contains a data member a. The class B uses the extends keyword to derive from class A. It also contains a data member b. A code snippet which demonstrates this is as follows:
class A {    int a = 9; } class B extends A {    int b = 4; } In the main() method in class Demo, an object obj of class B is created. Then the values of a and b are printed. A code snippet which demonstrates this is as follows:
public class Demo {    public static void main(String args[]) {       B obj = new B();       System.out.println("Value of a is: " + obj.a);       System.out.println("Value of b is: " + obj.b);    } }