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

public class Test<T>{

    static class MyTest{
        public MyTest(int k) {
            System.out.println("MyTest created");

    T obj1, obj2;

    public Test(T t, Class<T> cls) throws Exception {

        obj1 = t; // 1

        obj2 = cls.newInstance(); // 2

    public static void main(String[] args) throws Exception {
        MyTest mt = new MyTest(10);
        Test t = new Test(mt, MyTest.class);

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Sign Up Now
or Subscribe for future quizzes