Lecture 4: Objects; reference vs. primitive data types; type casting
lecture video
Classes and objects
- Procedural programming vs. object oriented programming
- creating and using objects
- constructors
- fields
- methods
- running programs with
main
Reference vs. primitive data types
- reference data types store the location of the data (an object)
- primitive data types store the actual data
Type casting
- explicit vs. implicit
- remember that Java is NOT dynamically typed (unlike Python)
Files used in class
Additional exercises
- Exercie R-1.10 from the book: Write a Java class,
Flower
, that has three instance variables of type String
, int
, and float
, which respectively represent the name of the flower, its number of petals, and price. Your class must include a constructor method that initializes each variable to an appropriate value, and your class should include methods for setting the value of each type and getting the value of each type.