In this case you seem to be both encapsulating and extending. Both are reasonable things to do but this is a mish-mash of the two. Which one you want depends on your specific use case so I shall explain both
Extending
This is a parent child relationship. In this case the child is a parent. Such as a Cat is a mammel. This would be achieved as follows
public abstract class CompoundExpression extends Expression {
public CompoundExpression(String first){
super(first);
}
//Other methods that make this class different from the parent class
}
Encapsulating
This is a "has a" relationship. For example a cat "has a" leg. In this case you do not need to use the "extends" keyword
public abstract class CompoundExpression{
Expression firstOperand, secondOperand;
public CompoundExpression(Expression first, Expression second){
this.firstOperand = first;
this.secondOperand = second;
}
//other methods to use the encapsulated Expressions
}
Extending and encapsulating the same class
This has its uses but is far less common than the above two; you need to be very careful, but as you mentioned it you can both extend a class and encapsulate one or more of that class. An analogy for this might be that a FemaleCat both is a cat and can contain cats (in the form of kittens). When doing this always act as if it is "a coincidence" that the class you encapsulate and the class you extend are the same
This would be as follows
public abstract class CompoundExpression extends Expression{
Expression firstOperand, secondOperand;
public CompoundExpression(String myString, Expression first, Expression second){
super(myString);
this.firstOperand = first;
this.secondOperand = second;
}
//other methods to make this class unique
}
As I say, I personally have never done this and it should not be considered the "default" way to encapsulation. Make sure you really know what you are doing before doing this
Conclusion
Given that a single CompoundExpression contains 2 seperate Expressions I suspect you want an encapsulating relationship