Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a Subclass [closed]

Tags:

java

oop

subclass

What is a "subclass" in java?

I know about classes and methods, but I do not know about subclasses.

like image 993
Master C Avatar asked May 02 '11 23:05

Master C


People also ask

What exactly is a subclass in Java?

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).

What is subclass and non subclass?

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.

What is a subclass in Python?

A class which inherits from a superclass is called a subclass, also called heir class or child class.

What is subclass and non subclass in Java?

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.


1 Answers

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.

like image 177
Jeremy Avatar answered Sep 22 '22 14:09

Jeremy