两种方法把类和对象写在同一个文件内

package ch07;

/**两种方法把类和对象写在同一个文件内
* Created by liwenj on 2017/7/20.
*/
//1
public class Cell {
String pp;

void cd() {
System.out.println("品牌是" + pp + "可以充电");
}

public static void main(String[] args) {
Cell PP = new Cell();
PP.pp = "华为";
PP.cd();

}
}

//2
public class Cell {
String pp;

void cd() {
System.out.println("品牌是" + pp + "可以充电");
}

}

class TestCell {
public static void main(String[] args) {
Cell PP = new Cell();
PP.pp = "华为";
PP.cd();

}
}

posted @ 2017-07-20 09:48  斯丢皮德曼  阅读(238)  评论(0编辑  收藏  举报