What is a "subclass" in java?
I know about classes and methods, but I do not know about subclasses.
In the Java language, classes can be derived from other classes, thereby inheriting fields and methods from those classes. Definitions: A class that is derived from another class is called a subclass (also a derived class, extended class, or child class).
A subclass is a class that describes the members of a particular subset of the original set. They share many of characteristics of the main class, but may have properties or methods that are unique to members of the subclass. You declare that one class is subclass of another via the "extends" keyword in Java.
A class which inherits from a superclass is called a subclass, also called heir class or child class.
In Java, it is possible to inherit attributes and methods from one class to another. We group the "inheritance concept" into two categories: subclass (child) - the class that inherits from another class. superclass (parent) - the class being inherited from.
A subclass is a class that extends another class.
public class BaseClass{ public String getFoo(){ return "foo"; } } public class SubClass extends BaseClass{ }
Then...
System.out.println(new SubClass().getFoo());
Will print:
foo
This works because a subclass inherits the functionality of the class it extends.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With