内部类
说明:
java中:内部类纯属于类的—(new)
//外部类
class Out {
private int age = 12;
//内部类
class In {
public void print() {
System.out.println(age);
}
}
}
public class Demo {
public static void main(String[] args) {
Out.In in = new Out().new In();
in.print();
//或者采用下种方式访问
/*
Out out = new Out();
Out.In in = out.new In();
in.print();
*/
}
}
引用:http://www.cnblogs.com/nerxious/archive/2013/01/24/2875649.html
scala中:内部类纯属于对象的(属于外部类的实例本身)
val outer1=new Outer1.Inner("Scala")
例子
package kmust.hjr.learningScala09
/**
* Created by Administrator on 2015/7/14.
*/
class Outer(val name:String){
outer=>class Inner(val name:String){
def foo(b:Inner)=println("Outer: "+outer.name+" Inner:"+b.name)
}
}
object OOPInScala {
def main(args:Array[String]){
val outer1=new Outer("Spark")
val outer2=new Outer("Hadoop")
val inner1=new outer1.Inner(" Scala")
val inner2=new outer2.Inner(" Java")
inner1.foo(inner1)
inner2.foo(inner2)
}
}