原创文章,转载请注明出处!

原文地址: http://www.ptbird.cn/2016/07/19/scala-chuji-demo-15/

There I am,in the world more exciting!

by postbird

www.ptbird.cn



package com.ptbird.scala /** * Created by postbird on 2016/5/25. */ //包对象 package object people{ val defaultName="scala" } package people{ class people{ var name=defaultName } } // people中的所有的类可以直接访问包对象的成员和方法 package spark.navigation { abstract class Navigator2 { def act } class Navigator {} package tests { //子包 用来做测试 class NavigatorSuite } package impls { class Action extends Navigator2 { def act = { println("action") } } } } package hadoop { package navigation { class Navigator } package launch { class Booster { val nav = new navigation.Navigator //都在 hadoop这个包里面 // 因此访问这个包的时候不需要写 hadoop.navigation,Navigator } } } object PackageTest { def main(args: Array[String]): Unit = { println(people.defaultName) //scala } }