Ask Question
2 January, 07:27

Suppose that a class named Bicycle contains a private nonstatic integer namedheight, a public nonstatic String named model, and a public static integer namedwheels. Which of the following are legal statements in a class named BicycleDemothat has instantiated an object as Bicycle myBike = new Bicycle (); ?

(a) myBike. height = 26;

(b) myBike. model = "Cyclone"

(c) Bicycle. int = 3 3;

(d) myBike. Wheels = 3

(e) my Bike. model = 108;

(f) Bicycle. wheels = 2

(g) Bicycle. height = 24;

(h) Bicycle yourBike=myBike

+4
Answers (1)
  1. 2 January, 11:08
    0
    (b) myBike. model = "Cyclone"

    (f) Bicycle. wheels = 2

    (h) Bicycle yourBike=myBike

    Explanation:

    Option (b) is legal statement because the model is a public variable and therefore it is legitimate to use class instance to access the value of model.

    Option (f) is legal statement because the wheels is a static variable and it can be accessed through the Bicycle class.

    Option (h) is legal statement because can create a new Bicycle class instance, yourBike and assign it with an existing class instance myBike.

    In Java, a private variable within a class cannot be directly accessed through class or class instance and therefore the option (a) and (g) are not true.

    The keyword int is a data type and it can be used as a instance name as in option (c).

    Java is case sensitive and therefore the option (d) is not true because of the uppercase letter "W" found in "Wheels" which doesn't match the attribute name wheels.

    The option e is an illegal statement as it should have spacing between my and Bike
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Suppose that a class named Bicycle contains a private nonstatic integer namedheight, a public nonstatic String named model, and a public ...” in 📙 Engineering if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers