What is the output of the following program:class Test<T> { // An object of type T is declared T obj; Test(T obj) { this.obj = obj; } // constructor public T getObject() { return this.obj; }} // Driver class to test abovepublic class Main { public static void main(String[] args) { // instance of Integer type Test<Integer> iObj = new Test<Integer>(15); System.out.println(iObj.getObject()); // instance of String type Test<String> sObj = new Test<String>("Java Lab"); System.out.println(sObj.getObject()); }}Select one:a. 15b. Java Labc. Compilation Errord. 15Java Lab
Question
What is the output of the following program:class Test<T> { // An object of type T is declared T obj; Test(T obj) { this.obj = obj; } // constructor public T getObject() { return this.obj; }} // Driver class to test abovepublic class Main { public static void main(String[] args) { // instance of Integer type Test<Integer> iObj = new Test<Integer>(15); System.out.println(iObj.getObject()); // instance of String type Test<String> sObj = new Test<String>("Java Lab"); System.out.println(sObj.getObject()); }}Select one:a. 15b. Java Labc. Compilation Errord. 15Java Lab
Solution
The output of the program will be:
15 Java Lab
So, the correct answer is d. 15Java Lab.
Similar Questions
class Test<T> { // An object of type T is declared T obj; Test(T obj) { this.obj = obj; } // constructor public T getObject() { return this.obj; }} // Driver class to test abovepublic class Main { public static void main(String[] args) { // instance of Integer type Test<Integer> iObj = new Test<Integer>(15); System.out.println(iObj.getObject()); // instance of String type Test<String> sObj = new Test<String>("Java Lab"); System.out.println(sObj.getObject()); }}Select one:a. 15Java Labb. 15c. Java Labd. Compilation Error
What is the output of the following program:class Test { // A Generic method example static <T> void genericDisplay(T element) { System.out.println(element.getClass().getName() + " = " + element); } // Driver method public static void main(String[] args) { // Calling generic method with Integer argument genericDisplay(11); // Calling generic method with String argument genericDisplay("Java Lab"); // Calling generic method with double argument genericDisplay(1.0); }}Select one:a. Compilation errorb.11Java Lab1.0c. No outputd.java.lang.Integer = 11java.lang.String = Java Labjava.lang.Double = 1.0
What is the Output of following Java Program?abstract class Demo{ public int a; Demo() { a = 10; } abstract public void set(); }class Test extends Demo{ final public void get() { System.out.println("a = " + a); } public static void main(String[] args) { Test obj = new Test(); obj.get(); }}Select one:a.Compile Time Errorb.a=10c.Runtime Exception
What is the output of this program? class A { public int i; private int j; } class B extends A { void display() { super.j = super.i + 1; System.out.println(super.i + " " + super.j); } } class inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } }2 23 3Runtime ErrorCompilation Erro
What will be the output of the following code snippet?public class MyClass { static int value = 10; public void printValue() { System.out.println(value); } public static void main(String[] args) { MyClass obj = new MyClass(); obj.printValue(); }}Question 4Answera.0b.10c.Compilation errord.Runtime exception
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.