SJSU/Udacity CS046

Lesson 2 - Objects

  1. Introduction
  2. Introducing Ellora
  3. Why OOP is Important
  4. Objects
  5. Objects Demo
  6. Quiz: Mariner 4
  7. Classes
  8. Quiz: Match the Methods
  9. Drawing Pictures
  10. Quiz: What Does This Method Do?
  11. Variables
  12. Variable Names
  13. Quiz: An Exercise on Variable Names
  14. Variable Types
  15. Quiz: Variable Types
  16. Initial Values
  17. Quiz: Initial Values
  18. Comments
  19. Quiz: How Many Days
  20. Quiz: Adding Comments
  21. Quiz: Variable Declarations: The Fine Print
  22. Variable Values Can Change
  23. Public Interfaces
  24. Public Interfaces 2
  25. Arguments and Return Values
  26. Quiz: Arguments and Return Values Exercise
  27. Method Declarations
  28. Quiz: Method Description
  29. Quiz: More Method Descriptions
  30. Constructing Objects
  31. Making Rectangles
  32. Quiz: Constructing Rectangles
  33. String Methods
  34. Quiz: The replace Method
  35. Quiz: The trim Method
  36. Quiz: toUpperCase and toLowerCase
  37. Accessors and Mutators
  38. Quiz: Accessor or Mutator?
  39. Quiz: Accessor or Mutator? 2
  40. Quiz: Pitfall
  41. Shared Objects
  42. Quiz: Copying Rectangles
  43. Quiz: Copying Strings
  44. Quiz: Copying Numbers
  45. Implementing a Test Program
  46. Quiz: Test Program
  47. Why It's Important to Test Your Code
  48. More About Graphics
  49. Quiz: Draw a Crate
  50. Quiz: Write Top Secret
  51. Quiz: Intro to Color
  52. Colors
  53. Matching Color
  54. An Interesting Project Ellora Worked On
  55. Ellora's Advice to You
  56. Conclusion

Quiz: Variable Declarations: The Fine Print

In your answers, use the letters a - g (without parentheses) for the following descriptions:
a) variable names can only contain letters and numbers
b) it's always a good idea to include an initial value
c) variable type doesn't match initial value type
d) variable has a bad type
e) no mistake
f) variable declarations need a semicolon
g) variable declarations must have types

var x = 13; d This was an error in 2013 when this course was produced. As of Java 10 in 2018, you can use var with variable declarations. Then the compiler figures out the correct type—in this case, int—from the initial value.
int x = "13"; c x is an int, but "13" is a String.
double x = 13.0 f Always put a ; after a variable declaration!
int lucky number = 13; a You cannot have a space in a variable name.
x = 13; g The type int is missing.
int x; b This is not an error, but it is a good idea to initialize variables when you declare them.
int luckyNumber = 3; e This variable declaration is practically perfect in every way.

Problem on this page?

Your name:

Your email address:

Problem description:

To protect against spam robots, please answer this simple math problem:
× =