zoukankan      html  css  js  c++  java
  • Java:thinging in java p158 exercise 1

    Create a class with a String field that is initialized at the point of definition, and another one that is initialized by the constructor. What is the difference between the two approaches.

     1 class Test{
     2     String s1;
     3     String s2="hello world";
     4     String s3;
     5     Test(){
     6         s3="hello java";
     7     }
     8 }
     9 public class ConstructorTest {
    10 
    11     public static void main(String[]args){
    12         
    13         Test t=new Test();
    14         System.out.println(t.s1);
    15         System.out.println(t.s2);
    16         System.out.println(t.s3);
    17         
    18     }
    19 }

    输出

    null
    hello world
    hello java
  • 相关阅读:
    C#
    C#
    C#
    创建一个ROS包
    创建一个工作空间
    ROS的文件系统
    单一职责原因
    策略模式
    UML类图
    简单工厂模式
  • 原文地址:https://www.cnblogs.com/taoxiuxia/p/4438783.html
Copyright © 2011-2022 走看看