❌ A. Max Integer: 4 Max Double: 3.3 ❌ B. Max Integer: 2 Max Double: 2.2 ❌ C. Max Integer: 1 Max Double: 1.1 ✅ D. Compilation error ❌ E. Runtime error
Explanation: 1. Method Overloading with Generics: • There are two overloaded findMax methods, one using extends Number and the other using extends Comparable<T>. • findMax(List<T extends Number>): Compares Number values using doubleValue() for comparison. • findMax(List<T extends Comparable<T>>): Compares values using the compareTo method, which is available for all classes implementing Comparable.
2. Type Inference and Ambiguity: • When the findMax method is called with List<Integer> or List<Double>, Java tries to infer which method to use. • Both Integer and Double implement Comparable<T>, so both methods are applicable. • This results in a method ambiguity error because Java cannot decide whether to use doubleValue() or compareTo() to compare the elements.
3. Compilation Error: • The ambiguity occurs because the Comparable interface is implemented by both Integer and Double, which causes the compiler to be unable to choose between the two overloaded methods.
❌ A. Max Integer: 4 Max Double: 3.3 ❌ B. Max Integer: 2 Max Double: 2.2 ❌ C. Max Integer: 1 Max Double: 1.1 ✅ D. Compilation error ❌ E. Runtime error
Explanation: 1. Method Overloading with Generics: • There are two overloaded findMax methods, one using extends Number and the other using extends Comparable<T>. • findMax(List<T extends Number>): Compares Number values using doubleValue() for comparison. • findMax(List<T extends Comparable<T>>): Compares values using the compareTo method, which is available for all classes implementing Comparable.
2. Type Inference and Ambiguity: • When the findMax method is called with List<Integer> or List<Double>, Java tries to infer which method to use. • Both Integer and Double implement Comparable<T>, so both methods are applicable. • This results in a method ambiguity error because Java cannot decide whether to use doubleValue() or compareTo() to compare the elements.
3. Compilation Error: • The ambiguity occurs because the Comparable interface is implemented by both Integer and Double, which causes the compiler to be unable to choose between the two overloaded methods.
Correct answer: D
BY Explanations “Top Java Quiz Questions”
Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283
Bitcoin is built on a distributed digital record called a blockchain. As the name implies, blockchain is a linked body of data, made up of units called blocks that contain information about each and every transaction, including date and time, total value, buyer and seller, and a unique identifying code for each exchange. Entries are strung together in chronological order, creating a digital chain of blocks. “Once a block is added to the blockchain, it becomes accessible to anyone who wishes to view it, acting as a public ledger of cryptocurrency transactions,” says Stacey Harris, consultant for Pelicoin, a network of cryptocurrency ATMs. Blockchain is decentralized, which means it’s not controlled by any one organization. “It’s like a Google Doc that anyone can work on,” says Buchi Okoro, CEO and co-founder of African cryptocurrency exchange Quidax. “Nobody owns it, but anyone who has a link can contribute to it. And as different people update it, your copy also gets updated.”
At a time when the Indian stock market is peaking and has rallied immensely compared to global markets, there are companies that have not performed in the last 10 years. These are definitely a minor portion of the market considering there are hundreds of stocks that have turned multibagger since 2020. What went wrong with these stocks? Reasons vary from corporate governance, sectoral weakness, company specific and so on. But the more important question is, are these stocks worth buying?