- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are Java parent and child classes in Java?
Java supports inheritance, an OOPs concept where one class acquires the members (methods and fields) of another.
You can inherit the members of one class from another, use the extends keyword as:
class A extends B{}
The class which inherits the properties of other is known as child class (derived class, sub class) and the class whose properties are inherited is known as parent class (base class, superclass class).
Following is an example which demonstrates inheritance. Here, we have two classes namely Sample and MyClass. Where Sample is the parent class and the class named MyClass is the child class.
Example
class Sample{ public void display(){ // Java Arrays with Answers System.out.println("Hello this is the method of the super class"); } } public class MyClass extends Sample { public void greet(){ System.out.println("Hello this is the method of the sub class"); } public static void main(String args[]){ MyClass obj = new MyClass(); obj.display(); obj.greet(); } }
Output
Hello this is the method of the super class Hello this is the method of the sub class
- Related Articles
- Parent and Child classes having same data member in Java
- What are Java classes?
- What are final classes in Java?
- What are abstract classes in Java?
- What are inner classes in Java?
- What are wrapper classes in Java?
- What are the differences between Java classes and Java objects?
- Can JavaScript parent and child classes have a method with the same name?
- What are anonymous inner classes in Java?
- What are I/O classes in Java?
- Is parent child hierarchy important on throws while overriding in Java?
- Are the private variables and private methods of a parent class inherited by the child class in Java?
- What are method local inner classes in Java?
- Why static methods of parent class gets hidden in child class in java?
- What are the different types of classes in Java?

Advertisements