Multiple choice technology programming languages

package polymorphism; class TestPolymorphismSuper { int p; TestPolymorphismSuper testPoly() { TestPolymorphismSuper TS = new TestPolymorphismSuper(); TS.p =100; return TS; } } public class TestPolymorphism1 extends TestPolymorphismSuper{ TestPolymorphism1 testPoly() { TestPolymorphism1 TSub = new TestPolymorphism1(); TSub.p =500; return TSub; } public static void main(String[] args) { TestPolymorphismSuper TSuper = new TestPolymorphism1(); TSuper = TSuper.testPoly(); System.out.println(TSuper.p); } }

  1. 500

  2. 100

  3. 0

  4. Null Pointer Exception

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The subclass TestPolymorphism1 overrides the testPoly() method. The reference variable TSuper is polymorphic and points to an instance of TestPolymorphism1. Calling TSuper.testPoly() invokes the overridden subclass method, which returns an object with p = 500. Printing TSuper.p prints 500.