当前位置:编程学习 > JAVA >>

java中,静态方法如何返回本身类型的类对象,看例子。我这样返回对不对?

class Test { public static void main(String[] args) { Color color = getColor(); } } class Color { public Color getColor { return new Color(); } }
追问:类里的方法是这样的:
 class Test
{
   public static void main(String[] args)
  {
   Color color = Color.getColor();
  }
}

class Color
{
  public  static Color getColor
  {
    return new Color();
  }
}public class Test
{
   public static void main(String[] args)
  {
   Color color = Color.getColor();
  }
}

class Color
{
  public  static Color getColor
  {
    return new Color();
  }
}
这样对不?
答案:Color color = getColor();这里有错

getcolor不是这个类里的方法 所以找不到这个方法!
其他:首先你要有那个接受类对象的变量吧? 你那样趣 都不知道你是要取得类的名字还是地址,
还有,你说说你要他的用途干嘛?  静态类还要他的对象?  一般我们要用他里面的方法,或者变量,
不是直接可以类名+方法么?? 3.4-1.4=                7.82-7.2=               2.19+9.1=       
10.1-0.89=              0.68+0.42=              8.1-5.1=   
0.728-0.24=             0.8+0.18=               0.89-0.25=     
1-0.98=                   0.048+0.52=               5×400=
19.9+11.1=               187÷1000=                 1+3.89=
 0.081×10=                 75÷10=                    0.96÷0.8=
0.8×7=                1.5×7=                 1.32×8=
0.7×8=                10.3×2=                5×0.6=
0.9×0.3=              3.5×0.2=               2.01×0=
10×0.05=              0.13×7=                0.21×100=
0.7×4=                0.05×4=                4×0.3=430-250=                     0.17+0.06=                  1.02-0.09=

7200÷800=                   0.17+0.6=                   0.83-0.6=

17×300=                     0.98-0.09=                   0.2+0.78=

600×700=                    10.2+0.02=                  0.15+0.7=

670+250=                     10.2+0.2=                   9.2-6=

8500÷500=                   3.2-3.2=                    3.7+2.3=

25×100=                     3.2-0.32=                   2+2.8=

380-290=                     0.35+0.5=                   0.35+0.63=

3500÷70=                    3.1+3=                      3.8+0.38=

7500÷250=                   3.8+1=                      0.95-0.05=

450+780=                     3.1+0.3=                    3+0.3=

630÷9=                      4.5-0.4=                     9.5-5=

330×9=                      9.53-1.53=                  9.5-0.5=

3.5+2.4=                      1-0.95=                     0.3+0.27=

0.47+0.13=                    4.5+4=                      4-0.6=

0.95+0.05=                    2.5+3.2=                    0.74+0.16=

23×100=                     9.8-4.8=                     480÷40=

0.53÷100=                   5.1+2.3=                     125×80=

0.078÷10=                   0.52+0.4=                    70×12=

0.25×100=                   3.4-2.8=                      0.6-0.37=

0.052×10=                   10+0.08=                    1-0.75=

0.5×1000=                   7.82+0.3=                    13.5+6.5=

3.05×100=                   1.2-0.8=                     21.6-12.6=

63÷100=                     0.83-0.5=                    0.76+0.14=

80÷1000=                    2.7+0.4=                    0.72-0.43=

30×100=                     0.92-0.2=                    3.5+4.8=

3.5+2.4=                      5+0.07=                     1-0.61=

0.47+0.23=                    0.25+0.75=                  3.7+0.33=

0.51+0.33=                    1-0.6=                       8-4.6=

5.8-3.6=                       0.52+0.4=                   6.45+5.5=

4.5-1.3=                       3.4-2.8=                     9.53-1.53=

8.8-6.7=                       10+0.08=                    9.5-7.3=

7.2+0.8=                      7.82+0.3=                    8.8-6.7=

9.5-7.3=                       1-0.95=                      3.4-2.8=

0.96-0.35=                     9.53-1.53=                   0.25+0.75=

1.2-0.8=                       0.83-0.5=                     2.7+0

12.5×8=               2.3×4=                 3.25×0= 
0.4×50=               30×0.1=                2.6×3=
4.1×2=                0.35×0.2=              7.5×0.1= 
2.5×2=       0.5×10=        0.6×8=         2.1×2=
2.8×10=      0.7×0.8=       0.04×20=        5.6+0.4=
4.7+2.3=       4.5×2=        6.9-2.5=       7.2×0.8=     
6×3.4=       0.62-0.32=     1.4×0.5=        0.75×100=
0.02×0.5=     3.6×0.3=       6.3÷7=          5.6×100=
0.75÷0.25=     0.125×8=       4.8÷0.3=        0.86÷2=
0.56÷28=      0.36÷0.4=      0.64÷0.8=       0.7×9=
3.6÷24=       0.8×1.1=       7.2+12.8=        46.7-3.8=
12.8÷4=       5.2÷13=        12.5÷5=        1.64+4.1=
10÷20=        24÷15=         8.65×10=      0.35×0.6=
3.08×0.01=      4.95×1000=     6.9×0.1=      0.4×0.5=
2.4÷0.8=       10.8÷9=        9.6÷0.8=       0.108÷2=
4.95÷0.9=       9.65÷0.1=      0.325×100=      2.5×8=
0. 56÷0.7=      0.125×4=      3.28×0.1=      3.9÷0.13=
7.2×0.1=        0.01×0.1=       0.25×0.4=     1.6÷0.8=
1÷2.5=         1.25×0.8=       3.2÷0.04=       0÷1.7=
0.22×102=     9.6÷0.8=       5×0.24=        4.5-0.05=
3.9÷0.13        16.5÷0.5=       5×0.12=         24×0.5=
4.8×0.5=        2.8+4.2=        0.84÷2.1=        5÷0.25=
7.8÷0.01=        5.4÷0.6=        3.2÷5=           7×0.62=
0.56÷0.8=        7.4-2.8=       0.18÷0.2=         0.16÷8=
4.5×0.02=        8+7.2=        1.2×30=         0.012×0.2=
7.3×0.3=          0÷6=        3.6÷0.12=        7.8÷0.6=
2÷5=            4.5+5=        0.3÷0.6=        0.96÷0.2=
10.5×0.4=        7.3+0.27=     8×0.125=        0.54÷0.6=
0.61+0.39=       0.56÷28=      10÷20=         4.08÷0.4=     
10-9.4=         0.8×0.11=      7.2+12.8=      5.6÷0.01=
2.3×100=        0.75×100=      0.108÷2=       10.8÷9=
7.8÷0.01=        5.4÷0.6=        3÷5=           7×0.62=
12÷0.5=         5.2×0.4=       12.2÷0.2=       5.6÷100=
0.41+3.7=       0.02×0.5=       7.2-0.8=        1.4×0.5=
84÷0.21=        0.75÷0.25=     2.5×16=         0.108÷2=
1.75+32.5=      16-5.07=       5.2÷13=         1.64÷41=
1.02×0.2=       0.26×0.3=       8.4×0.02=        1.2×6=
0.8×0.05=       12.6÷0.03=      8.71÷0.1=        21÷0.21=
0.8×0.13=       0.34÷17=        8.08÷0.4=         0.5×2.2=
1.24×4=        3.27+0.63=       5.02×0.3=        0.3×0.5=     
5.6÷7=         72÷ 7.2=     0.7÷0.35=          0.7÷1.4
0.48÷0.04=      1.25÷2.5=        5.5+5.5=        16.8÷8=
0.54+2.2=       3.5-0.05=       2÷0.02=         0.25×40=
1.5×0.6=        0.32÷0.8=       12.25÷0.5=       73.5×0.1=
46.5+52.5=     0.45×102=     1.25×88=     2.64+3.85+1.54=     
8×1.25=      7÷3.5=      4.2÷0.7÷6=       0.4×8.6×25=
0.27÷0.3=   2.5×101=    0.65×101-0.65=     2.6×7÷2.6×7=
0.02×0.5=     3.6×0.3=       6.3÷7=          5.6×100=
7.8÷0.01=       5.4÷0.6=        3.2÷5=           7×0.62=
1.5×0.6=       0.32÷0.8=       12.25÷0.5=       73.5×0.1=
2.5×2=      0.5×10=        0.6×8=         2.1×2=
0.61+0.39=    0.56÷28=      10÷20=         4.08÷0.4= 
 1.2×0.3 =     6.6÷1.1 =      4.9÷7=           0÷0.48= 单例模式?错! right. 

上一个:手机JAVA系统有哪些
下一个:java 适合做什么项目?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,