package com.bjsxt.com;import java.util.Scanner;
public class Test{
public static void main(String []args){
Run run=new Run();
run.method1();
}
}
class People{
private String name;
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
public void getMessage(){
System.out.println("The name of people is:"+name);
}
}
class Run{
private static Run run=new Run();
private People people=new People();
private static Scanner sc=new Scanner(System.in);
public void method1(){
run.method2();
System.out.println("in method1:");
people.getMessage();
}
public void method2(){
run.method3();
}
public void method3(){
System.out.println("Please input the name of people");
people.setName(sc.nextLine());
System.out.println("in method3:");
people.getMessage();
}
}
public class Test{
public static void main(String []args){
Run run=new Run();
run.method1();
}
}
class People{
private String name;
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
public void getMessage(){
System.out.println("The name of people is:"+name);
}
}
class Run{
private static Run run=new Run();
private People people=new People();
private static Scanner sc=new Scanner(System.in);
public void method1(){
run.method2();
System.out.println("in method1:");
people.getMessage();
}
public void method2(){
run.method3();
}
public void method3(){
System.out.println("Please input the name of people");
people.setName(sc.nextLine());
System.out.println("in method3:");
people.getMessage();
}
}
解决方案 »
- 请教各位高手多文档编辑的记事本怎么处理保存文本这个功能,谢谢
- 谁能帮我解决几个问题啊,谢谢
- 麻烦大家帮我看看这个内存溢出怎么解决
- Vector 类稳定性如何呢?
- 前辈门,教教我~~~~~~~~~在线等哦
- java程序如何读取声音文件(不用Applet,而是一般的java application程序中.....)
- Eclipse为什么不会出现IDE界面
- 为什么getTableName()只能得到空格或者空?
- 关于jbuilder中querydataset查询数据库的问题
- 急求助!怎样解决无法实例化?
- JAVA做的语音识别
- toByteArray是ByteArrayOutputStream 的方法吗
static Test4 t=new Test4();//为什么加上static就能正确运行 如果把static去掉运行会报错 这是为什么啊?
public Test4(){
}
public static void main(String []args){
Test4 t1=new Test4();
}
}我加了注释的那一句谁能给我解释解释啊?
静态(static)和非静态的区别:静态是和类有关的,在类加载的时候产生,而非静态是和对象有关的,对象产生的时候非静态属性才产生,非静态方法能调用静态方法和静态属性。而静态方法只能调用静态方法和静态属性。