View RSS Feed

Casting

Java Casting

  1. Object Reference Type Casting

    by , 03-02-2012 at 05:27 PM
    In Java object typecasting, type cast of 1 object reference is possible to another object reference. Suck type of casting is done with superclass, subclass or class types. Compile time rules or runtime rules are present in Java for casting.

    Class relationship is the basic thing at which Object reference is dependent. Any object reference could be assigned to reference variable of type object because the object class is usually the superclass, for each Java class.

    Two ...
    Tags: type casting Add / Edit Tags
    Categories
    Casting
  2. Type casting

    by , 01-08-2012 at 12:50 PM
    When you treat a variable of one type to another type, it is called type casting. Up casting supports automatic conversion but in case of low casting you need to explicitly specify it.

    Java Code: Type Casting
    byte -> short -> int -> long -> float -> double
    int i = 5;
    long j = i; //Right. Up casting or implicit casting
    byte b1 = i; //Wrong. Compile time error “Type Mismatch”.
    byte b2 = (byte) i ; //Right. Down casting or explicit casting is required.
    ...

    Updated 01-14-2012 at 07:46 PM by Core Java

    Categories
    Casting