Huawei
Company
Programming
Technical
Find the wrong option
Class B extends A
a)A a=new A();
b)B b=new B();
c)A a=new B();
d)B b=new A();
Read Solution (Total 4)
-
- here classB extends Class A;
it means we are creating a Class B(THAT IS EXTENDING CLASS A) therefore in classB we have all the features of class A HENCE WE CAN CREATE OBJECTS FROM CLASS B(sub class) to super class(ClassA)
B b = new B();//correct assignment i.e we are creating object for sub class(B) in sub class itself
A a = new A();//correct assignment i.e we are creating object for super class(A) in sub class itself(which has Class A features)
A a = new B();//creating object for sub class in super class which is not possible y bcz in superclass there is no class B features where as in class B has Class A features so i think ther is no way in creating a sub class object in super calss so option C is incorrect
B b = new A();//IN SUB CLASS we are creating object for super class which is possibele - 9 years agoHelpfull: Yes(12) No(3)
- We know that to the super class reference (for Eg. Object Class ) we can assign sub class object.
So here A is the super class and B is the sub class.So we can assign B(sub class) object to A(super class reference).
A a =new B(); is correct assignment.
So, a),b),c) are correct.
Therefore d) option is the wrong assignment.
So d) is the answer.Hare Krishna - 9 years agoHelpfull: Yes(9) No(7)
- d is the correct amswer
- 8 years agoHelpfull: Yes(2) No(0)
- A a = new B();
- 6 years agoHelpfull: Yes(1) No(0)
Huawei Other Question