匿名類物件及可變引數
阿新 • • 發佈:2019-02-15
1、匿名類物件的呼叫,僅僅使用一次;
new objectname().method;
2、可變引數 String ... args
package com.test.args; public class TestArgs { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub new TestArgs().sayHello(); new TestArgs().sayHello("suwenqing"); new TestArgs().sayHello(new String[]{"hello world","hello beijing"}); } public void sayHello() { System.out.println("hello world"); } public void sayHello(String args) { System.out.println(args); } /* public void sayHello(String[] args) { System.out.println(args); } */ public void sayHello(String ... args) { for(int i=0;i<args.length;i++) { System.out.println(args[i]); } } }