Menu
Question Index
...

Is program compiles or not?

public class GenericsType<MC> {
    new MC();
    MC t;
    public void set(MC t1) {
        t = t1;
    }
    public static void main(String args[]) {
        GenericsType<String> type = new GenericsType<String>();
        type.set("Merit Campus");
    }
}


Program compiles successful.
Compilation Error because we can not create object for MC.
Compilation Error because in set() we are not give this.t = t1;.
Compilation Error or Runtime Error for some other reason.

Doubts

Problems

Topic: Java Generics In Methods And Constructors

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App