To make the code compile you can declare X's return type as Object. This will work as everything is an object. However it is bad design!
You factory (method X) is creating objects of both types because they have something in common. If they are not related at all then why they need to be created in the same method?
In OOP you express this commonality by a base class or an interface and let the factory return then common type.
public abstract class Account {}
public class SavingsAccount extends Account {}
public class TransactionAccount extends Account {}
public Account Create(int type)
{
if(type == 0)
return new SavingsAccount();
else
return new TransactionAccount();
}