Java tutorial
//package com.java2s; //License from project: Apache License public class Main { /** * Print class name and its parent name of an object * * @param obj */ public final static String getClassInheritence(Object obj) { if (obj == null) { return null; } StringBuilder stb = new StringBuilder(); Class<?> cls = obj.getClass(); String name = cls.getSimpleName(); stb.append("["); stb.append(String.valueOf(obj)); stb.append(":"); while (!name.toLowerCase().equals("object")) { stb.append(name); stb.append("<-"); cls = cls.getSuperclass(); name = cls.getSimpleName(); } stb.append("]"); return stb.toString(); } }