0

What I would like to do is extend a class based on what is in the constructor. Is this possible? With my limited knowledge of java this would be the best example of what I'm trying to do.

public class Test extends extendClass {

    Object extendClass;

    public Test(Object extendClass){
        this.extendClass = extendClass;
    }

}

EDIT: What I would like is to have a sort of modular class that extends another class that is defined in the constructor I'm just using the constructor as an example. What I would be doing is running the code of the super class and then running mine as well. Also Object is just an example as well I know the class that I'm going to be extending.

  • 3
    No, inheritance is a compile time concept. You're trying to do it at run time. – Sotirios Delimanolis Apr 19 '14 at 20:39
  • @SotiriosDelimanolis isn't it possible using generics? – maxx777 Apr 19 '14 at 20:43
  • @maxx777 If they clarified what they want, maybe there is a solution in generics. – Sotirios Delimanolis Apr 19 '14 at 20:45
  • @user2500587 do u know `Object` is itself a class that is inherited by all other class. and your code is not quite clear what actually u wanna do. you have used name `extendClass` for two different variables and a class name as well. – maxx777 Apr 19 '14 at 20:52
  • I do know that Object is inherited by all other classes I'm not THAT new to java. If you look at the constructor again I'm using the constructor as an example I'm referencing the Object that is in the class and setting it to the one in the constructor. –  Apr 19 '14 at 20:55

1 Answers1

0

Stuff like this should be possible with Aspect Oriented Programming, for which in Java there exists AspectJ. I wouldn't go there though if you're still a beginner in Java.

wvdz
  • 16,251
  • 4
  • 53
  • 90