What will be the result of compilation and execution of the following code:

package X;
public class X<X> {
    X x;
    public X(){  }
    public X(X x){ 
        this.x=x;
    }
    public <Y extends X> Y Y(Y y){
        return y;
    }
}

class Y<Y extends X> extends X{
    private static Integer Y = 5;
    public static void main(String...X){
        System.out.print(new X().Y(Y).toString());
    }
}
Explanation
When invoking method " public <Y extends X> Y Y(Y y)" it can receive any object as an argument. Y in this method does not have any relation to the class that was defined later in code. While instantiating X no generic type was given, so, any object can be used as an argument.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback