What will happen as a result of the following code?

class A {}
class B extends A {}

public class Test { 
    static public  void main(String args[]) {
        B b = new B();
        A a = b;
        if (a.hashCode() == b.hashCode())
            System.out.print("Passed");
    }
}
Explanation
References a and b indicate the same object, so the console displays the message "Passed". A class specimen can be assigned to the specimen of a class B due to polymorphism.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback