Object casting in java
Object casting in java: A b = (C)d A - Class or Instance Name b - Reference Variable Name C - Class or Instance Name d - Reference Variable Name 3 Golden rules: Rule 1 : (checked by compiler) There should be parent/child relation between C and d, object reference d should be child or parent of Class C else compiler will throw inconvertable compilation error. Eg: String o=new String("hellboymaddi"); StringBuffer b=(StringBuffer)o; In the above example, reference variable o is of String type and there is no parent & child relationship with String Buffer,so it will raise compilation error and exact message is: inconvertible types found: java.lang.String required: java.lang.StringBuffer Rule 2: (Checked by compiler) We are assigning class C to Class A,so Class c Should be equal to Or child Class of A, else compiler will throw incompatible compilation error. Eg: Object o=new String("hellboymaddi"); String b=(StringBuffer)o; In th...