1 / 8

CSCI 224

CSCI 224. Scope – Package – Access. Scope. Scope refers to accessing members (including inherited ones) from code within a class. Class scope and block scope While there are explicit modifiers in Java to control access there are some specific rules that also apply. Golden Rule of Scope.

Download Presentation

CSCI 224

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI 224 Scope – Package – Access

  2. Scope • Scope refers to accessing members (including inherited ones) from code within a class. • Class scope and block scope • While there are explicit modifiers in Java to control access there are some specific rules that also apply.

  3. Golden Rule of Scope • That static code cannot access non-static code by their simple names. • References this and super are not available. • An object has knowledge of it’s class, therefore static members are always accessible in a non-static context.

  4. What is static code • Static members belong to the class, not an instance of the class • Class variables • Class methods • When a class is first initialized, the static members are created once. • Ie. Public static void main (String[] args) • This applies also to static initializer blocks also (to be discussed later)

  5. Variables and Scope • Class variables • Instance variables • Local • Live only within the block that they are created in. When the block ends – so do they. • Remember, variables declared in a method signature are local.

  6. Packages • A package is an encapsulation method used to group classes, interfaces and sub-packages. • Package MUST be the first line in a source file. And become part of the fully qualified name

  7. Naming scheme • The global naming scheme proposed is to use the internet domain name to identify packages. • Edu.heartland.csci130 • Package level access • Access to otherwise unrestricted members • Is the default level

  8. Access Levels • Private • Protected • Default • Public • Other Modifiers • Abstract • Synchronized • Final

More Related