Make a class names Foo Add a class variable to foo called x and initialize it to 5 Add an instance variable to foo called y and initialize it to 100   Make an instance of the class, call it f Using Foo., print out the value of x  (proper etiquette for class variables) Using f., Print out the value of  y (proper etiquette for instance/self. variables)   Hint: remember that class variables are the ones where their value is the same for all instances/clones.  And instance variable (which you declare inside the __init__ method with the self. preface, are unique to each clone.  When you print a class variable the proper way is to use classname . (for example Foo.x) and when you print an instance variable you use the instance handle (for example f.y.)

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter4: More Object Concepts
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question

python3:

Class vs Instance variable

 

  1. Make a class names Foo
  2. Add a class variable to foo called x and initialize it to 5
  3. Add an instance variable to foo called y and initialize it to 100

 

  1. Make an instance of the class, call it f
  2. Using Foo., print out the value of x  (proper etiquette for class variables)
  3. Using f., Print out the value of  y (proper etiquette for instance/self. variables)

 

Hint: remember that class variables are the ones where their value is the same for all instances/clones.  And instance variable (which you declare inside the __init__ method with the self. preface, are unique to each clone.  When you print a class variable the proper way is to use classname . (for example Foo.x) and when you print an instance variable you use the instance handle (for example f.y.)

 

Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage