Docsity

Access Modifiers - Introduduction to Jave Programming - Lecture Slides, Slides of Java Programming

Partial preview of the text

Download Access Modifiers - Introduduction to Jave Programming - Lecture Slides and more Slides Java Programming in PDF only on Docsity!

Access modifiers and

more on methods

Announcements

HW 2 due today (now) HW 3 posted

public vs private

public vs private

The public modifier allows any class anywhere to access the variable/method The private modifier only allows access in the class where the variable/method is defined (See: RunSuperDouble.java)

public vs private

public vs private

Overloading

When overloading, Java will still convert types automatically (int to double) But this will only happen if there is not already a match for the current type If the computer cannot decide on the best conversion, the code will not run (See: BadOverload.java)

Constructors

Whenever you make a Class type (with new) you have used a constructor method For example: Scanner input = new Scanner(System.in); Constructors always have the same method name as the class and are only run (once) when you make a variable of that Class type (See: Constructor.java) Docsity.com