62.1k views
1 vote
Consider the classes below, declared in the same file: class A { int a; public A() { ​ a = 7; } } class B extends A { int b; public B() { ​ b = 8; } } Which of the statements below is false? Group of answer choices After the constructor for class B executes, the variable a will have the value 7. A reference of type A can be treated as a reference of type B. Both variables a and b are instance variables. After the constructor for class B executes, the variable b will have the value 8.

User Jbouwman
by
5.3k points

1 Answer

2 votes

Answer:

2. A reference of type A can be treated as a reference of type B - False

Base class or its objects are not related to their derived class (or its objects).

Step-by-step explanation:

class A {

int a;

public A() {

a = 7;

}

}

class B extends A {

int b;

public B() {

b = 8;

}

}

///////////////////////////////////////////////////////////////////////////////////////////////////////

1. After the constructor for class B executes, the variable a will have the value 7 - True.

When an object of a derived class is declared, the constructor of base class is called before the constructor of derived class (is called).

3. Both variables a and b are instance variables - True.

Classes can have instance, or member, variables and methods.

4. After the constructor for class B executes, the variable b will have the value 8 - True.

When object of class B is declared, its constructor was called, which initialized variable b to 8.

User ElDuderino
by
5.0k points