Can a variable be assigned different type in java?
<p>I was wondering if it's possible in Java to have a variable that can potentially be different types? To be specific, I have two different objects of different class, both of them are tables. So let's say we have:</p>

<pre><code>TableTypeA t1;
TableTypeB t2;
</code></pre>

<p>Let's say that both classes have a method called getSelectedRow(), is it possible for me to make a third variable so that I can do the following:</p>

<pre><code>SomeType t3;
t3 = t1; 
t3.getSelectedRow();

t3 = t2;
t3.getSelectedRow();
</code></pre>

<p>TableTypeA and TableTypeB do not extend the same class, the closest common superclass they have do not have the getSelectedRow() method. Seeing how similarly they function, one of them should probably be extending the other or their classes should've been merged together, but let's say a structural change like that is not an option, is what I'm suggesting possible to do?</p>

<p>Thanks.</p>

<p>Edit: I think I will add an interface for these, thank you very much for all of the quick responses!</p>
