0

When we create a Java class for example B that inherits from another class e.g. A, we say that our subclass (B) extends the super class (A). What is this act called in programming. Simply put, for example, when a teacher wants to show this to their student, how should they say this? For example, can they say "Well, now I inherit B from A" or "I extend B from A" or "I make B extend A" or "I subclass B from A"?
P.S.
For example in the following Java code (in Android):

public class customFragment extends Fragment {
        public void Test(){

        }

        @Nullable
        @Override
        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
            return super.onCreateView(inflater, container, savedInstanceState);
       }
}

I want to show my student that I'm making customFragment a subclass of Fragment by extending Fragment. Please note that I'm looking for a transitive verb to describe the act of making B inherit A, e.g. making B a subclass of A.

  • 1
    I think they all work in their own way. – Tim Biegeleisen Jun 17 '17 at 11:22
  • 3
    they all are correct and In generic we can say like this also without using technical term :- "B is the child class of A" or "A is the parent class of B" – shivam Jun 17 '17 at 11:28
  • "Inherits (from)" is a synonym for "implements" and "extends", though the latter two are not synonyms for each other. "Inherits" is less precise; "inherits", "descends from", and "subtype (subclass, subinterface) of" often refer to indirect inheritance, i.e., descent from a subclass of the supertype. The exact usage for any of these terms might be imprecise with respect to whether direct inheritance is meant. Use "directly" or "indirectly inherits" if you want to be clear. "extends" should always mean "directly". "implements" should mean directly, but in practice doesn't always. – Lew Bloch Jun 17 '17 at 21:18
  • 2
    Is your question more oriented for Java, or for OOP in general ? By default I would go for "inherits". – Walfrat Jul 26 '17 at 11:45
  • @Walfrat Java, but i guess any OOP language will do. – codezombie Jul 26 '17 at 11:48
2

According to the language spec

The optional extends clause in a normal class declaration specifies the direct superclass of the current class.

...

A class is said to be a direct subclass of its direct superclass. The direct superclass is the class from whose implementation the implementation of the current class is derived.

So, in your example, B is a direct subclass of A; A is the direct superclass of B.

And since there ain't a noun that can't be verbed, you would then say "B directly subclasses A". (But I don't think you'd ever say "A directly superclasses B").

Unless you're really interested in the "directness" here, it is more usual to say that B is a subclass of A (B subclasses A); A is a superclass of B. (Note the indefinite article in the second half here; a class may have many superclasses, but just one direct superclass).

There are a number of examples with terminology in the linked section of the language spec which may be useful.

Of course, the language spec is a somewhat dry document, and some people may not stick to its exact wording (myself included). I would probably say that "B extends A", because that's​ literally what it says in the code, or "B indirectly extends A" if A isn't the direct superclass.

Ultimately, if you say "B extends A", "B subclasses A", "B is a subclass of A", "B is a child of A" etc, you will almost certainly be understood.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.