public class Food static int count private String flavor sweet Food count void

Public class food static int count private string

This preview shows page 3 - 5 out of 5 pages.

public class Food { static int count; private String flavor = "sweet"; Food() { count++; } void setFlavor(String s) { flavor = s; } String getFlavor() { return flavor; } static public void main(String[] args) { Food pepper = new Food(); System.out.println(pepper.getFlavor()); } } Select one: a. a class variable b. a constructor c. a local object variable d. an instance variable e. a method Feedback Your answer is correct. See Section 5.1.1 of Eck (2014). Question 4 Correct Mark 1.00 out of 1.00 Flag question Question text Consider the following Java program, which one of the following best describes "count"? public class Food { static int count; private String flavor = "sweet";
Food() { count++; } void setFlavor(String s) { flavor = s; } String getFlavor() { return flavor; } static public void main(String[] args) { Food pepper = new Food(); System.out.println(pepper.getFlavor()); } } Select one: a. a class variable b. a constructor c. a local object variable d. an instance variable e. a method Feedback Your answer is correct. See Section 5.1.1 of Eck (2014). Question 5 Correct Mark 1.00 out of 1.00 Flag question Question text Consider the following Java program, which one of the following best describes "pepper"? public class Food { static int count; private String flavor = "sweet"; Food() { count++; } void setFlavor(String s) { flavor = s; } String getFlavor() { return flavor; }
static public void main(String[] args) { Food pepper = new Food(); System.out.println(pepper.getFlavor()); } } Select one: a. an object b. a reference c. null d. sweet e. The program does not compile. Feedback Your answer is correct. Object variables store references, not the values of the objects themselves. See Section 5.1.2 of Eck (2014).

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture