17

I am new to java and I am trying to create an XML document and clone a specific node (minus the textnode) of this document over and over again. Someone answered me and said that I should subclass the node and override the cloning. So my question is what is sub-classing?

dreamcrash
  • 47,137
  • 25
  • 94
  • 117
codenamejupiterx
  • 1,589
  • 9
  • 23
  • 34

4 Answers4

22

Subclassing means to define a new class that has the properties of an old class (the "superclass") with some changes.

In this case, your original responder is saying something like this:

Say you have a base class Base which has a method getTwo like so:

class Base {
   public int getTwo(){ return 2;}
}

You decide you want a new class that still have a method getTwo but that returns the string "two" instead of the number 2. You could define it as

class Subclass extends Base {
   public String getTwo() { return "two"; }
}

We say Subclass is a subclass of -- or more commonly, "is a kind of" -- Base.

Beyond that, you'd be best off to read a book on object-oriented programming with Java. I'm fond of Thinking in Java, which has the added advantage that it's available freely on line.

Charlie Martin
  • 110,348
  • 25
  • 193
  • 263
6

@Charlie Martin has explained what subclassing means.

However, it is not clear that you've been given good advice. If you are creating the XML document by assembling a DOM in memory, a better approach would be to create a helper class with static methods that perform the sequence of DOM node operations that you need to do.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

In short Answer : A Superclass can be Subclassed - That means for a specific class we can find/create a subclass that extend it.

user1207965
  • 129
  • 1
  • 10
0

Subclass represents is a relationship in Object-Oriented Programming (Inheritance).

For example
The Circle is a Shap.
So we can say:
The Circle class is a subclass of Shape class.

Ahmed Nabil
  • 17,392
  • 11
  • 61
  • 88