+ 1

What happens when you call methodOfA() in the below class?

class A { int methodOfA() { return (true ? null : 0); } }

2nd Jul 2017, 5:43 PM
Arpita Chatterjee
Arpita Chatterjee - avatar
2 odpowiedzi
+ 2
You'll get a nullPointerException. The methods return type is int but, return (true ? null : 0) will always return null which is an incompatible type with int.
2nd Jul 2017, 6:00 PM
ChaoticDawg
ChaoticDawg - avatar