-1 Developer John · September 5, 2014
Hi again! This is the second thing I was wondering about this week. How can I inherit variables or strings? I know when I create a new method with a print line statement inside of it, I can override the print statement or just receive it from another class. I'm wondering how this works for variables and strings though. As of right now, I'll go ahead and start with Java Gui Interfaces, but am hoping for a reply soon.

-Thank you!8-)

Post a Reply


Oldest  Newest  Rating
0 Developer John · September 7, 2014
0 Devon Horton · September 8, 2014
Sorry, having trouble determining what it is your looking for.  Are you looking for a way to inherit variables such as strings from a parent class? 
+2 Devon Horton · September 9, 2014
Sorry about that, it seems when I hit Shift+Tab it posted the reply. I'll continue here.

Are we talking about an Abstract parent? If not,

public class Parent{
    protected String type;


public class Child extends Parent{

By doing it like this Child will inherit the variable 'type'. Each instance of Child will now have the variable type. 
0 Developer John · September 9, 2014
I know I should use the "Extends"  Java keyword, but what if I'm following a certain API? 
Like this:

public class subclass extends JavaPlugin{

Ok yes, why did you put protected?:wassat:
+3 Devon Horton · September 9, 2014
The 'protected' Modifier allows the member 'type' to be accessed from Child/Sub classes. Where as if we'd have declared that with the modifier private it would not access-able to the sub-class. I'm finishing up Physics homework atm, I'll try to get to the other question in a moment. 
0 Developer John · September 10, 2014
Lol done yet?8-):wassat::D;)
+1 Devon Horton · September 11, 2014
Following a certain API as in wanting to extend a certain class of the API such as Font(out of awt)?  

If so:

public class CustomFont extends Font{
public CustomFont(){
super("KillerCustomerFont", Font.ITALIC,14); //Makes a call to Font's constructor


If you extend a class that has a constructor with arguments, then you must call super yourself. 

If that is not what you were talking about let me know..I feel as if I misunderstood what it is you're looking for..

EDIT: Or when you say API are you referring to Graphics APIs?
0 Developer John · September 12, 2014
No, I mean, would if I'm following an API for a game. Can I still inherit variables from that class? For an example:
public class Game extends JavaPlugin {

JavaPlugin makes a plugin for the game in order for me to modify the game, yet it doesn't allow me to extend Game to Game2 because Game is already extending JavaPlugin. Like this:
public class Game extends Game2 {

What can I do? I want to inherit variables that contain modified parts of the game so that I can save lots of time not trying to restate every variable., yet having multiple classes for my program. Is it possible to extend 2 classes?
0 Irving Santiago · September 12, 2014
You have to extend class Game and modify it to your needs. If the system does not allow it then the class Game has been declared as final. Classes declared final cannot be extended or sub-classed. 
0 Developer John · September 12, 2014
Would if I used implements instead of extends?
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator