Java tutorial
//package com.java2s; public class Main { public static String getClassNameInStr(Object obj) { Class<?> enclosingClass = obj.getClass().getEnclosingClass(); if (enclosingClass != null) { return enclosingClass.getName(); } else { return obj.getClass().getName(); } } }