• java getName() getClass()用法


    In java there is a way that makes us enabled to get the object class name at runtime. It can be done by calling the getClass() method on the class object. Then  by calling the method getName() we can get the name of the object class.

    In our example java program we have created a class RoseIndia and we have created an object of this class. Now we will be calling method getClass() on this object to get the class. 

    roseIndiaObject.getClass() returns the runtime class.  roseIndiaObject.getClass().getName() gets the class name of the created object at runtime. Here is the full java code of program which will be getting the object's class name as follows:

    public class RoseIndia
    {
      public RoseIndia(){
      System.out.println("Constructor Called");
      }
      public static void main(String args[])
      {
      RoseIndia roseIndiaObject = new RoseIndia();
      System.out.println("Object's Class name =>"+
       roseIndiaObject.getClass().getName());
      }
    }

    输出:

    Constructor Called
    Object's Class name =>RoseIndia

    tructor Called

    Object's Class name =>RoseIndia

     

  • 相关阅读:
    mysql find_int_set
    PHPSTROM8.0 注册码(7.1也可用)
    gym 101657 D
    gym101657 C
    poj 3525
    poj1279
    poj3335
    poj 1228
    poj 1873
    poj 2074
  • 原文地址:https://www.cnblogs.com/youxin/p/2711043.html
Copyright © 2020-2023  润新知