User Input, Exceptions, and Reading and Writing Text Files

User Input, Exceptions, and Reading and Writing Text Files

15-121 Fall 2020 Margaret Reid-Miller

Today

? Homework3: is available ? due Monday September 21th at 11:55pm

? From last time: Encapsulation ? Reading User Input ? Handling exceptions ? Reading a text file ? Writing to a text file

Fall 2020

15-121 (Reid-Miller)

2

Writing classes

What 3 things may appear inside a class?

fields constructors methods What should I determine first?

the fields Think: "What does my object need to remember?"

How do you declare a field?

_p_r_iv_a_t_e_ ____ _____; type name

Fall 2020

15-121 (Reid-Miller)

3

Inside a constructor or non-static method, what variables does it have access to?

1. local variables declared inside the method 2. parameters 3. fields

In a static method, we cannot access __fie_l_d_s__.

(or anything that isn't static without creating an object first)

What are Java's visibility modifiers?

Fall 2020

15-121 (Reid-Miller)

4

Classes (and their parts) have visibility modifiers:

? public: accessible to everyone ? protected: inside package, inside class,

inside subclass ? package-private (default, no modifier used):

inside package, inside class ? private: accessible only within the class

Fall 2020

15-121 (Reid-Miller)

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download