The object type conversion java

Transition between the basic data types:

  • Automatic conversion: smaller data types can be automatically converted to uppercase data type;
  • Cast: large data can be converted into small data types Type: float = (float) 32.0;

public class Person extends Object{}

public class Student extends Person{}

Mandatory for java objects into shape:

  • May be performed from subclass to superclass automatic type conversions;
    Student Student new new S = ();
    the Person P = S;
    String A = "Hello";
    Object obj = A;
  • Can not be converted into the parent subclass; unless the reference to the parent class is that subclass, namely:
    the Person new new Student P = ();
    Student S = (Student) P;
    otherwise:
    Object OBJ1 = "World";
    String = A1 (String) obj1;
  • No inheritance relationship between type conversion reference is illegal;:

Guess you like

Origin www.cnblogs.com/xiximayou/p/12049540.html