View RSS Feed

fatabass

Using of Class Class. An Example:

Rating: 1 votes, 1.00 average.
by , 01-28-2012 at 11:30 AM (878 Views)
Java Code:
package myPackage1;

interface HasBatteries{};
interface Waterproof{};
interface Shoots{};

class Toy
{
	Toy(){};
	Toy(int i){};
}

class FancyToy extends Toy implements HasBatteries,Waterproof,Shoots
{
	FancyToy()
	{
		super(1);
	}
}

public class ToyTest 
{
	static void printInfo(Class cc)
	{
		System.out.println("Class name: " + cc.getName()
				+ " is interface? " + cc.isInterface());
		System.out.println("Simple name: " + cc.getSimpleName());
		System.out.println("Canonical name: " + cc.getCanonicalName());
		System.out.println();
	}

	public static void main(String[] args) 
			throws ClassNotFoundException, InstantiationException, IllegalAccessException 
	{
		Class c = Class.forName("myPackage1.FancyToy");
		printInfo(c);
		
		for(Class interfaces: c.getInterfaces())
			printInfo(interfaces);
				
		Class up = c.getSuperclass();
		Object obj = null;		
		
		obj = up.newInstance();
		printInfo(obj.getClass());
		System.out.println(obj.getClass());
		System.out.println(obj.toString());
	}
}

Submit "Using of Class Class. An Example:" to Facebook Submit "Using of Class Class. An Example:" to Digg Submit "Using of Class Class. An Example:" to del.icio.us Submit "Using of Class Class. An Example:" to StumbleUpon Submit "Using of Class Class. An Example:" to Google

Tags: None Add / Edit Tags
Categories
Uncategorized

Comments