Saturday, September 27, 2014
Sample
public class ClassDemo {
public static void main(String[] args) {
try {
ClassDemo cls = new ClassDemo();
Class c = cls.getClass();
// class object associated with BaseClass
Class bClass = BaseClass.class;
// checks whether BaseClass is assignable from ClassDemo
boolean retval = bClass.isAssignableFrom(c);
System.out.println("Return Value = " + retval);
// checks whether ClassDemo is assignable from BaseClass
retval = c.isAssignableFrom(bClass);
System.out.println("Return Value = " + retval);
}
catch(Exception e) {
System.out.println(e.toString());
}
}
}
// base class
class BaseClass extends ClassDemo {
public BaseClass() {
// no argument constructor
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment