why i am getting ClassCastException in this case

2012-02-08T18:46:21

Please tell me why i am getting ClassCastException in this case

I have type casted , the source of B class to A as shown below , but why i am still getting ClassCastException here .

public class A extends B 
{


}

public class B {
    public String getData() {
        return "B";
    }
}


public class Main {
    public static void main(String args[]) {
        A a = new A();
        B b = new B();
        a = (A) b;
        System.out.println(a.getData());
    }
}

Copyright License:
Author:「user663724」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/9191784/why-i-am-getting-classcastexception-in-this-case

About “why i am getting ClassCastException in this case” questions

Please tell me why i am getting ClassCastException in this case I have type casted , the source of B class to A as shown below , but why i am still getting ClassCastException here . public class A
I have two very simple classes, one extends the other: public class LocationType implements Parcelable { protected int locid = -1; protected String desc = ""; protected String dir ...
On running the following snippet : String hqlSelect = "select bookID from Issued where regID = " + regID; List list = sess.createQuery(hqlSelect).list(); Iterator i = list.iterator(); ...
I am new to Jenkins. I am getting the following error. Please help FATAL: hudson.scm.SCMRevisionState$None cannot be cast to hudson.scm.SVNRevisionState java.lang.ClassCastException: hudson.scm.
I'm creating an android application and i'm trying to use a PreferenceActivity. I'm getting the java.lang.ClassCastException: java.lang.String error when it gets to this line return PreferenceMana...
I am implementing the google analytics in my android app. While accessing the Application class from mainactivity the following error is coming: java.lang.RuntimeException: Unable to start activity
I have this class named RiddlesHolder: public class RiddlesHolder extends Application { ArrayList<String> funnyRiddles = new ArrayList<String>(); ArrayList<String>
I am calling the Volley but there is a ClassCast exception occurring. Below i have shared the code. RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext()); //
I have the following classes defined: enum FruitTypeEnum { APPLE, BANANA, NONE } // POGO class FruitDTO { FruitTypeEnum fruitType } // Hibernate Entity abstract class Farm {
I wrote this sample code that I extracted from a library that I'm making because it is causing a java.lang.ClassCastException and I don't understand why. Here's the code: interface Event data class

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.