Monday, 13 February 2017

UnCheckedException : CloneNotSupportedExcept





public class CloneNotSupportedExcept {


    public static void main(String[] args) throws CloneNotSupportedException {
        CloneDemo2 cd2 = new CloneDemo2();        System.out.println(cd2.salary);
        AnotherClass ac = new AnotherClass();        System.out.println(ac.gradeLetter);
        AnotherClass y = (AnotherClass) ac.clone();        System.out.println(y.gradeLetter);    }
}
class CloneDemo2 implements Cloneable {
    double salary = 50000.0;
}

class AnotherClass implements Cloneable {
    char gradeLetter = 'C';
    public Object clone() throws CloneNotSupportedException {
        return super.clone();    }
}

No comments:

Post a Comment