Menu
Topics Index
...
`

Creating Generic Class Method and Variables1710


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating Generic Class Method and Variables1710
What is the output of the following program?
class MyClassA<U> {
    U _;
    public MyClassA(U str) { _ = str; }
    public U get_() { return _; }
}
class MyClassB<T, V> extends MyClassA<V> { // LINE A
    public MyClassB(V v) { super(v);  }
    public String myMethod() {
        V input = get_();
        String inputString = input.toString();
        String result = "";
        for (int i = inputString.toCharArray().length; i > 0; i--) {
            int ch = inputString.toLowerCase().toCharArray()[i - 1];
            int newNumber = 0;
            while (ch > 0) {
                newNumber = newNumber * 10 + ch % 10;
                ch = ch / 10;
            }
            result += ((char) ((newNumber / 65) + 66));
        }
        return result;
    }
}
public class Manmohan {
    public static void main(String[] args) {
        MyClassB<Integer, StringBuilder> obj = new MyClassB<Integer, StringBuilder>(new StringBuilder("MERIT"));
        System.out.println(obj.myMethod());
    }
}

A. 7371706577
B. KIHCO
C. JHGBN
D. Compilation Error at LINE A
E. Compilation Error at some other place
F. Runtime Error
Topic: Java Generics

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans is B on calling Mymethod MERIT is converted to char array ans is traversed back. T is converted to lower case whose ascii value is returned 116 den the number is reversed 611 den 611/65 gives 9,9+66 gives 75 which is K similarly all others

Posted by Teja Potlapally    2014-03-12 13:02:23


Answer is E..Compilation error at some other place..it is in while loop...

Posted by Sneha Rapool    2014-03-12 17:04:36


Congratulations Teja Potlapally. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-03-13 04:28:57


© meritcampus 2019

All Rights Reserved.

Open In App