Question: I have two variables with a height and width value, like so:

```
var height = 1080
var width = 1920

```

I know I'm about to get the ratio by doing `width/height` which gives me something like this: `1.7794253938832252`

The problem I'm having is I want to get the aspect height/width, ultimately I want to get `16:9` or `3:2` purely based on the height and width values of an image. I don't want to resize it, I just want to know what it should be based on the values of height and width. 

How would I calculate this?

Answer: 
make abstract your class A and the getX(); method.

```
public class Test {
    public static void main(final String[] args) {
        B b = new B();
        b.print();
    }
}

abstract class A {

    protected abstract int getX();

    public void print() {
        System.out.println(getX());
    }
}

class B extends A {
    private final int x = 10;

    @Override
    protected int getX() {
        return x;
    }
}

```

and override the toString method in place of your print method

```
@Override
public String toString() {
    return String.valueOf(getX());
}

```

the final code

```
public class Test {
    public static void main(final String[] args) {
        B b = new B();
        System.out.println(b);
    }
}

abstract class A {

    protected abstract int getX();

    @Override
    public String toString() {
        return String.valueOf(getX());
    }
}

class B extends A {
    private static final int X = 10;

    @Override
    protected int getX() {
        return X;
    }
}

```

you could also define as static your x variable

But as say Andrew Tobilko you can consider also to use an interface if A doesn't represent a stateful entity.

It's certainly the best solution for your case, mix the use of an interface and an abstract class

```
public class Test {
    public static void main(final String[] args) {
        B b = new B();
        System.out.println(b);
    }
}

interface MyInterface {
    int getX();
}

abstract class A implements MyInterface{
    @Override
    public String toString() {
        return String.valueOf(getX());
    }
}

class B extends A {
    private static final int X = 10;

    @Override
    public int getX() {
        return X;
    }
}

```
You could make the parent class abstract, eliminate the property in the parent class, make getX() abstract, and then leave print() as concrete. Then just use the concrete implementation of getX() in the child class.