The use of class classes in Java

Source: Internet
Author: User

1  Packageclasstest;2 3 /**4 * How to represent an instance object of a class, that is, a class type, there are three methods, or you can create an object instance of a class from a class type5  * @authorWang6  *7  */8  Public classClassDemo1 {9      Public Static voidMain (string[] args) {Ten          One         //how the instance object of Foo is represented, Foo1 is represented. AFoo foo1 =NewFoo (); -          -         //Foo This class is also an instance object, the Class class instance object, how to express, any class is an instance object of class, this instance object has three kinds of representations the         //the first representation---> actually tells us that any class has an implied static member variable class -Class C1 = Foo.class; -  -         //the second type of representation---> already knows that the object of the class is through the GetClass method +Class C2 =Foo1.getclass (); -  +         //The Third Way of expression---> dynamically load classes through the Class.forName method AClass C3 =NULL; at         Try { -C3 = Class.forName ("Com.imooc.reflect.Foo"); -}Catch(ClassNotFoundException e) { -             //TODO auto-generated Catch block - e.printstacktrace (); -         } in  -         /* to * Official website C1, C2 indicates the class type of the Foo class (class type) Everything is object, class is an object, is an instance object of class + * This object we call the class type of the class -          */ the          *         //whether C1 or C2 represent the class type of the Foo class, a class can only be an instance object of class $SYSTEM.OUT.PRINTLN (C1 = =C2);Panax Notoginseng  -System.out.println (C2 = =C3); the  +         //We can create an object instance of the class entirely from the class type of the classes----> Create an Instance object of Foo from C1 or C2 or C3 A         Try { the             //need to have a parameterless construction method +Foo foo =(Foo) c1.newinstance (); - foo.print (); $}Catch(instantiationexception e) { $             //TODO auto-generated Catch block - e.printstacktrace (); -}Catch(illegalaccessexception e) { the             //TODO auto-generated Catch block - e.printstacktrace ();Wuyi         } the  -     } Wu } -  About classFoo { $  -     voidprint () { -System.out.println ("foo"); -     } A}

The use of class classes in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.