在一个源文件中编写4个类Hello、A、B和C,主方法包含在类Hello中,类A、B、C中各包含一个静态和非静态方法,在类Hello的主方法中分别调用类A、B、C中的方法。

在一个源文件中编写4个类Hello、A、B和C,主方法包含在类Hello中,类A、B、C中各包含一个静态和非静态方法,在类Hello的主方法中分别调用类A、B、C中的方法。
package com.majing;

public class HelloABC {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//A的非静态方法--------------------------
		A a = new A("I am");
		System.out.println(a.charAt(3));
		//A的静态方法
		System.out.println(A.atoi("123456"));
		
		//B的非静态方法--------------------------
		B b = new B(20);
		System.out.println(b.getB());
		//B的静态方法
		System.out.println(B.itoa());
		
		//C的非静态方法
		C c = new C(20.12f);
		System.out.println(c.getC());
		//C的静态方法
		System.out.println(C.atof("12.125"));
		
	}

}

class A{
	static public String _a;
	
	public A(String a){
		this._a = a;
	}
	
	public char charAt(int index){
		return _a.charAt(index);
	}
	
	public static int atoi(String b){
		return Integer.parseInt(b);
	}

}

class B{
	public static int _b;

	public B(int b){
		this._b = b;
	}
	
	public int getB(){
		return this._b;
	}
	
	public static String itoa(){
		return String.valueOf(_b);
	}
}	

class C{
	public float _c;

	public C(float c){
		this._c = c;
	}
	
	public float getC(){
		return this._c;
	}
	
	public static float atof(String a){
		return Float.parseFloat(a);
	}
}

你可能感兴趣的:(Java)