Given a base class and a derived class defined as follows
public abstract class BaseTest extends Object implements Runnable
public class AdvancedTest extends BaseTest
what will happen when we try to compile the following method?
1. public boolean checkTest( Object obj ){
2. if( obj instanceof BaseTest ) return true;
3. System.out.println( "Not a BaseTest" );
4. if( obj instanceof Runnable ) return true;
5. System.out.println( "Not Runnable" );
6. return false;
7. }
How can i get this code working and what is its answer? I tried coding it in the following manner but i can't get it working. Pl help
If there are any good examples of instanceOf and Gc please send them to may email id too. I am weak in those areas. Pl help.
coding:
abstract class BaseTest extends Object implements Runnable
{
public abstract boolean checkTest(Object obj);
};
public class AdvancedTest extends BaseTest
{
public static void main(
String[] args)
{
public boolean checkTest(Object obj)
{
if (obj instanceof BaseTest)
{
return true;
}System.out.println("NOt a base
test!");
if (obj instanceof Runnable)
{
return true;
}System.out.println("Not runnable.");
return false;
}
AdvancedTest a = new AdvancedTest();
String s = new String("Welcome");
boolean m=a.checkTest(s);
}
}
Thanks in advance
Padmini