-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNotes0923.txt
More file actions
49 lines (32 loc) · 970 Bytes
/
Notes0923.txt
File metadata and controls
49 lines (32 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Aim: How do we write our own constructors?
Do Now: What is the smallest variable type that could be used to store the
following values
1) 5
2) -30,000
3) 255
4) 5,000,000,000
Answers:
1) byte
2) short
3) short
4) long
Default Values
If a variable is not initialized it is given a default value.
All numeric primitives are set to 0
boolean primitives are set to false
Characters are set to '' (empty/null characters)
Strings are set to "" (empty/null string)
All object variables are set to null (nothing)
Constructor
Java creates a default constructor for every class.
The default constructor takes no parameters and will set all
instance variables to their default values.
You can write your own constructors using this header:
<protection> <class name>(<parameters>)
Constructors can be private or protected, but are most often public.
public Greeter() {
message = "Hello";
}
public Greeter( String m ) {
message = m;
}