My guesses are the bolded Are they right Questions 68 refer

My guesses are the bolded. Are they right?

Questions 6-8 refer to the following class hierarchy:

Square extends Quadrilateral

Quadrilateral extends Polygon

6.Which of the following is true?

This class hierarchy will cause an error since Square can only have one parent class.

When a Square is instantiated the constructors in Quadrilateral and Polygon are not called.

Square has access to all methods and variables in Quadrilateral.

Square does not have access to any methods in Quadrilateral or Polygon.

Square has access to all public methods and variables in Quadrilateral.

7. Which of the following statements must be true in order for Square to access the constructor in Polygon?

Square has access to all public methods and variables in Polygon and will never need to directly call a constructor.

The call to Polygon\'s constructor must be the last line in Square\'s constructor.

The call to Polygon\'s constructor must be the first line in Square\'s constructor.

Square must first access Quadrilateral\'s constructor, and Quadrilateral\'s constructor must call Polygon\'s constructor.

Square\'s constructor must be declared private.

9. If a class Shape is added, which of the following would make the most sense?

Shape should be a child of Square.

Shape should be a child of Quadrilateral.

Shape should be a child of Polygon.

Polygon should be a child of Shape.

Shape should not be included in the hierarchy.

Solution

6)Ans)Square has access to all public methods and variables in Quadrilateral.

Reason:Polygon is the super class.And Quadrilateral is the sub class of Polygon and Square is the sub class of Quadrilateral.

According to the concept of inheritance in java a sub class object can have an access to the all the methods and variables which are declared as public in the super class obejct.

In this way the answer is Square has access to all public methods and variables in Quadrilateral.

____________________

7)Ans)Square must first access Quadrilateral\'s constructor, and Quadrilateral\'s constructor must call Polygon\'s constructor.

Reason:

When we create the object to the Square class.Internally Square class constructor will be called.But Before that JVM will check whether is there any super class to that Square class.If yes,then the super class constructor will be called(Which is Quadrilateral class constructor. )

But before calling the Quadrilateral class constructor JVM will check is there is any Super class to Quadrilateral class.If yes then before calling the Quadrilateral class constructor Polygon class constructor is executed after that Quadrilated class constructor is executed,after that Square class constructor is executed.

In this way the correct answer is Square must first access Quadrilateral\'s constructor, and Quadrilateral\'s constructor must call Polygon\'s constructor.

_________________

8)Ans)Shape should be a child of Quadrilateral.

Reason:Quadrilateral by definition means it is having 4 sides.Square has 4 sides,Rectangle has 4 sides or rhombus has 4 sides.As we want to write the Shape class ,it is the best place if we write that class as sub class to the quadrilateral class.

__________________Thank You

My guesses are the bolded. Are they right? Questions 6-8 refer to the following class hierarchy: Square extends Quadrilateral Quadrilateral extends Polygon 6.Wh
My guesses are the bolded. Are they right? Questions 6-8 refer to the following class hierarchy: Square extends Quadrilateral Quadrilateral extends Polygon 6.Wh

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site