Java: Adding fields and methods to existing Class?

You can create a class that extends the one you wish to add functionality to:

public class sub extends Original{
 ...
}

To access any of the private variables in the superclass, if there aren’t getter methods, you can change them from “private” to “protected” and be able to reference them normally.

Hope that helps!

Leave a Comment

tech