0%

Where to use key word static?

  • method
  • field
1
2
3
4
5
6
7
8
9
10
11
12
public class Koala{
public static int count = 0; // static variable
public static void main(String[] args){ // static method
System.out.println(count);
}
}

public class KoalaTester{
public static void main(String[] args){
Koala.main(new String[0]);
}
}
Read more »

Write Methods

  • What is a method like?

method-signature

Element Value in nap() example Required?
Access modifier public no
Optional specifier final no
Return type void yes
Method name nap yes
Parameter list (int minutes) yes(can be empty)
Optional exception list throws InterruptedException no
Method body { // take a nap } yes(can be empty braces)
Read more »

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package aquarium; 
public class Water {
boolean salty = false;
}

package aquarium.jellies;
public class Water {
boolean salty = true;
}

package employee;
INSERT IMPORTS HERE
public class WaterFiller {
Water water;
}
Read more »