/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		GenericObject o;

        o = new Object1(10, 10);
        o.wh();
        System.out.println(o.w); // Output: 3 (ok)
        System.out.println(o.h); // Output: 10 (ok)

        o = new Object2(10, 10);
        o.wh();
        System.out.println(o.w); // Output: 7 (ok)
        System.out.println(o.h); // Output: 4 (ok)

        String inputFromUser = "1";
        
        // o = new Object + inputFromUser + (10, 10);
        /*I know that is an absurd, just to illustrate...
		if polymorphism can solve this problem, I thik it's the best option. So how use it here?
		I don't wanna use ifs or switchs, I will use more than 300 classes*/
		
		Class<?> typeFromUser = Class.forName("Object" + inputFromUser);
		java.lang.reflect.Constructor<?> constructor = typeFromUser.getDeclaredConstructor(Integer.TYPE, Integer.TYPE);
		Object obj = constructor.newInstance(10, 10);
		o = (GenericObject) obj;
		
        o.wh();
        System.out.println(o.w); // Output: 3 (that's what I wanna obtain)
        System.out.println(o.h); // Output: 10 (that's what I wanna obtain)
	}
}

abstract class GenericObject {
            int w, h, x, y;
            GenericObject (int x, int y) {
                this.x = x;
                this.y = y;
            }
            public abstract void wh();
        }
        class Object1 extends GenericObject{
            Object1 (int x, int y) {
                super(x, y);
            }
            @Override
            public void wh () {
                w = 3;
                h = 10;
            }
        }
        class Object2 extends GenericObject{
            Object2 (int x, int y) {
                super(x, y);
            }
            @Override
            public void wh () {
                w = 7;
                h = 4;
            }
        }