zoukankan      html  css  js  c++  java
  • 关于面向对象和String类型的 09,10

    package test.面试题;
    
    public class Test9 {
        public static void main(String[] args){
            Outer.Inner in=new Outer().new Inner();
            in.show();
        }
    }
    //补齐程序(注意:内部类和外部类没有继承关系)输出30 20 10
    class Outer {
        public int num = 10;
        class Inner {
            public int num = 20;
            public void show() {
                int num = 30;
                System.out.println(num);//
                System.out.println(this.num);//this.num
                //System.out.println(new Outer().num);//new Outer().num或Outer.this.num
                System.out.println(Outer.this.num);
            }
        }
    }
    package test.面试题;
    /*
     * 面试题:
     * 1、String,StringBuffer,StringBuilder的区别
     *     String是不可变的,StringBuffer与StringBuilder是可变de
     *     StringBuffer是同步的,数据安全,效率低;StringBuilder是不同步的,数据不安全,效率高
     *
     *2、StringBuilder和数组的区别?
     *    二者都可以看做是一个容器
     *    但是StringBuilder数据最终是一个字符串数据
     *    而数组可以防止多种数据,但必须是同一种数据类型的
     *
     *3、第三个面试题就是下面的题目。需要记住这点:
     *    String作为形式参数的时候,将它看成基本数据类型使用
     *    StringBuffer在方法中的赋值操作不会改变原来的值,但是方法造成的操作会改变它的值
     */
    public class Test10 {
        public static void main(String[] args){
            String s1=new String("hello");
            String s2=new String("world");
            System.out.println(s1+"---"+s2);//hello---world
            change(s1,s2);
            System.out.println(s1+"---"+s2);//world---worldworld 结果是hello-world
            System.out.println("--------------------------");
            StringBuffer sb1=new StringBuffer("hello");
            StringBuffer sb2=new StringBuffer("world");
            System.out.println(sb1+"---"+sb2);
            change(sb1,sb2);
            System.out.println(sb1+"---"+sb2);//hello---worldworld 
        }
        public static void change(String s1,String s2){
            s1=s2;//world
            s2=s1+s2;//worldworld
        }
        public static void change(StringBuffer sb1,StringBuffer sb2){
            sb1=sb2;//world
            sb2.append(sb1);//worldworld
        }
    
    }
  • 相关阅读:
    Enable Zombie
    python中调用c文件中的函数(ubuntu)
    NSNotificationCenter使用心得(原)
    TCP/UDP
    xcconfig 文件使用( 转 )
    TS流解析 (转)
    c 数字和char类型转换
    结构体如何使用NSData包装
    NSValue 保存定长的结构体
    遍历DOM的所有节点,输出宽度高度都大于50的元素节点名称
  • 原文地址:https://www.cnblogs.com/aigeileshei/p/5549348.html
Copyright © 2011-2022 走看看