5/26/2021 Java Subclass Example With Easy Explanation [ 2021 ]
INTERVIEW QUESTIONS JAVA JAVA PROGRAMS TEST CASES SELENIUM MANUAL TESTING DIFFERENCE
SoftwareTestingo » Java » Java Tutorial » SubClass In Java & Java Subclass Example
SubClass In Java & Java Subclass Example
Last Updated On: May 15, 2021 By Softwaretestingo Editorial Board
Search this website
Tutorials Important Links
Software Testing Jobs
Manual Testing Tutorial
Selenium Tutorial
Core Java Tutorial
TestNG Tutorial
What We Are Learn On This Post Java Programs
Selenium Programs
Manual Test Cases
Interview Tips
Contact US
www.softwaretestingo.com
Important Links
Software Testing Interview Questions
Subclass In Java Agile Interview Questions
Welcome to the post of Java tutorial. in our previous post, we have discussed inheritance in Java. And in Manual Testing Interview Questions
this post, we’re going to discuss subclass.
Testing Interview Questions
Selenium Interview Questions
Selenium Real Time Interview Questions
Selenium WebDriver Interview Questions
Automation Framework Interview Questions
Appium Interview Questions
https://www.softwaretestingo.com/explain-subclass-java/ 1/4
5/26/2021 Java Subclass Example With Easy Explanation [ 2021 ]
TestNG Interview
INTERVIEW QUESTIONS JAVA JAVA PROGRAMS TEST CASES SELENIUM MANUAL TESTING Questions
DIFFERENCE
Java Interview Questions
Core Java Interview Questions
Categories
Select Category
As we know that in Java every class is built from another Java class except the object class. Here the
newly created class is called a subclass. The important thing you need to remember is A subclass
inherits state and behavior from all of its ancestors.
Subclass Definition
A class that is derived from another class is called a subclass (also a derived class, extended class, or
child class). The class from which the subclass is derived is called a superclass (also a base class or a
parent class).
Define Subclass
When you are coming for an interview that time you may face technical java interview questions round
define subclass. So we are plan to share more information about the java subclass or subclass java in
detail.
What is a subclass in java?
When there is a relationship between two objects in Java, there a name given to the class that is
inheriting the methods and variables of the superclass. That’s why the subclass is a more specialized
version of the superclass. And the Subclass also called derived classes, child classes, or extended
classes.
how to create a subclass in java
To create a subclass we need to use the keyword “extends”. After that, you need to follow the “extends”
keyword with the parent class which you want to extend.
For Example:
Public class SubClassName extends ParentClassName
Advantages Of Using Subclass
There are several advantages of using Subclass in Java, like:
Reuse of code: Through inheritance, a subclass can reuse methods that already exist in a
superclass.
Specialization: In a subclass, you can add new methods to handle cases that the superclass does
not handle. You can also add new data items that the superclass does not need.
Change in action: A subclass can override a method that it inherits from a superclass by defining a
method of the same signature like that in the superclass. When you override a method, you might
make only a few minor changes or completely change what the method does.
Java Subclass Example
package com.java.Softwaretestingblog;
class superclass
{
public void show()
{
System.out.println("Parent Class");
}
}
public class SubclassExample extends superclass{
https://www.softwaretestingo.com/explain-subclass-java/ 2/4
5/26/2021 Java Subclass Example With Easy Explanation [ 2021 ]
SubclassExample()
INTERVIEW QUESTIONS JAVA JAVA PROGRAMS TEST CASES SELENIUM MANUAL TESTING DIFFERENCE
{
super.show();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
SubclassExample obj=new SubclassExample();
}
Output:
Parent Class
Ref: Article
Python Developer Boot Selenium Real Time English learning for Sapient Latest 2021
Camp - Enrolling Now Tricky Scenarios kids Selenium API Testing
- Start Today Interview Questions & Interview Questions
Explanation
Ad learncodinganywhere.com softwaretestingo.com Ad British Council India softwaretestingo.com
Machine Learning & AI CGI Manual Java IBM Selenium 2021 FIS 2021 Latest Best
Course - PG Selenium Automation New & Easy Interview Selenium Interview
Certi cation Interview Question Questions Questions
2021
Ad itvedant.com softwaretestingo.com softwaretestingo.com softwaretestingo.com
Filed Under : Java Tutorial
Leave a Reply
Your email address will not be published. Required fields are marked *
Comment
Name *
Email *
POST COMMENT
Copyright © 2021 SoftwareTestingo.com ~ Contact Us ~ Sitemap ~ Privacy Policy
https://www.softwaretestingo.com/explain-subclass-java/ 3/4
5/26/2021 Java Subclass Example With Easy Explanation [ 2021 ]
INTERVIEW QUESTIONS JAVA JAVA PROGRAMS TEST CASES SELENIUM MANUAL TESTING DIFFERENCE
https://www.softwaretestingo.com/explain-subclass-java/ 4/4