Multiple choice technology programming languages

Consider the following code snippet: class A: a = 1 def foo(self): print "Hello",self.a class B(A): a = 3 def foo(self): print "Hi",self.a A = B a = A() b = B() What is the value of a.foo()

  1. Error

  2. Hello 1

  3. Hi 3

  4. Hello 3

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

The line A = B reassigns the class name A to point to class B. Therefore, A() creates an instance of class B, and calling a.foo() executes B's foo method, which prints 'Hi 3'.