Java – Package and Access

  • example of common package
    • download
  • use class in package
    • import package
      • then use class inside that package
    • or
    • packagePath packageClassObject = new packagePath
      • exp. java.util.Scanner in = new java.util.Scanner(System.in);
    • never need to import java.lang(default package)
    • do not need to import class in same package
  • package name
    • recommend use domain name
    • can used to avoid name clash between class
    • should be unambiguous
  • uasge of Class A and B
    • A and B same package
      • B can create a A object
        • protected and non-mentioned type can use and modify
        • not to private type
    • A and B different package, B extend A
      • B can create a A object
        • B can use extended protected and new b protected
        • not to a and b `s private and non-mentionmed

留下评论