public class Test { main(String args []) { People people1 = new People(); people1.print(, ); } }
Êä³ö£º
ÎÒµ÷ÓÃÁËÁ½¸ö²ÎÊýµÄ·½·¨£¡
Èç¹û½«Test.javaÖеÄÓï¾ä»»³É£º
main(String args []) { People people1 = new People(); people1.print(); }
Êä³ö£º
ÎÒµ÷ÓÃÁËÒ»¸ö²ÎÊýµÄ·½·¨£¡
¡¾×¢Òâ¡¿º¯ÊýÖØÔØÖ»ºÍ²ÎÊýÀàÐͺͲÎÊý¸öÊýÓйأ¬ºÍ·µ»ØÖµÀàÐÍÎ޹أ¡£¡ ÀýÈçpublic void XXX()ºÍpublic String XXX()²»¹¹³ÉÖØÔØ£¡ £¨ÕâÒ²µ±È»»á±¨´í£¬ÒòΪÁ½¸öº¯ÊýÖظ´ÁË£©Í¬Ê±ÖØÔØÒ²ºÍ²ÎÊýµÄÃüÃûÎ޹أ¬ public void XXX(String str1)ºÍ public void XXX(String str2)ÊÇͬһ¸öº¯Êý£¬ÕâºÍº¯ÊýÖØÔؾ͸üûÓÐëÏß¹ØϵÁË
¹¹Ô캯ÊýÖØÔØ
ºÍº¯ÊýÖØÔصÄÌØÐÔÒ»Ö£¬µ«ÓÐÒ»¸öÓÐȤµÄÒ»µãҪעÒ⣺ µ±ÄãûÓÐдÈë¹¹Ô캯ÊýµÄʱºò£¬ÏµÍ³»áĬÈÏÌṩһ¸öÎ޲εĹ¹Ô캯Êý¸øÄ㣬 ËùÒÔ¾ÍËãûÓÐÏÔʽµØдtype ʵÀý = new type()Ò²ÊdzÉÁ¢µÄ
µ«ÊÇ£¡ µ±ÄãдÁËÒ»¸öÓвÎÊýµÄ¹¹Ô캯Êý£¬µ«ÓÖûÓÐдÎÞ²ÎÊýµÄ¹¹Ô캯Êýʱ£¬type ʵÀý = new type()¾Í»á±¨´íÁË£¡£¨ÒòΪĬÈϵÄÎ޲ι¹Ô캯ÊýÒѾ±»ÄãдµÄÓвÎÊýµÄ¹¹Ô캯Êý¸øÈ¡´úÁËÂï~~~~£©
ʵÀý±äÁ¿µÄĬÈÏÖµ£¬ºÍ³õʼ»¯ÊµÀý±äÁ¿
Èç¹ûÄãÉùÃ÷ÁËÒ»¸öʵÀý±äÁ¿£¬µ«Ã»Óгõʼ»¯Ëü£¬ÄÇôÕâ¸ö±äÁ¿»áÈ¡µÃÒ»¸öĬÈÏÖµ£¬Ä¬ÈÏÖµÒÀÀàÐ;ö¶¨£º
ÕâÊÇÿ¸ö»ù±¾ÀàÐͶÔÓ¦µÄĬÈÏÖµ
boolean (null) 0 long 0 £¨L£© float 0.0 £¨f£© double 0.0 £¨d£©
¶ÔÓÚÒýÓÃÀàÐÍ£¬Ò»Âɳõʼ»¯Îªnull
Àý×Ó£º
Default.java:
public class Default { private int number; private float f; private boolean bool; private char c; private byte b; public void printDefaultValues () { System.+ number); System.+ f); System.+ bool); System.+ c); System.+ b); } }
Test.java:
public class Test { main(String args []) { Default default1 = new Default(); default1.printDefaultValues(); } }
Êä³ö
intµÄĬÈÏÖµ:0 floatµÄĬÈÏÖµ:0.0 booleanµÄĬÈÏÖµ:false charµÄĬÈÏÖµ:
Ò»°ãÇé¿öÏ£¬×îºÃ¶ÔÒ»¸öʵÀý±äÁ¿½øÐгõʼ»¯£¬È¥¸²¸ÇµôĬÈÏÖµ
public class Default { private int number = 1; }
·ÃÎÊ˽ÓÐʵÀý±äÁ¿
˽ÓбäÁ¿µÄ·ÃÎÊ·½Ê½ÎÒ·Ö³ÉÁ½ÖÖ£º ÀàÄÚ·ÃÎʺÍʵÀý·ÃÎÊ
£¨Êµ¼ÊÉÏÁ½Õ߸ÅÄîÉÏÓн»²æ£¬µ«ÎªÁË·½±ã˵Ã÷ÎÒ½«Á½Õß·Ö¿ªÁË£©
ÀàÄÚ·ÃÎÊ£ºÔÚ¶¨ÒåÒ»¸öÀàµÄʱºò£¬ÔÚÀàÄÚ²¿·ÃÎÊ˽ÓбäÁ¿
ʵÀý·ÃÎÊ£º ´´½¨¶ÔÓ¦ÀàµÄÒ»¸ö¶ÔÏó£¬Í¨¹ý¶ÔÏó·ÃÎÊ
ʵÀý·ÃÎÊ
´´½¨µÄ¶ÔÏó²»ÄÜÖ±½Ó·ÃÎÊ˽ÓÐʵÀý±äÁ¿£¬µ«ÄÜͨ¹ý¹«ÓеķÃÎÊÆ÷·½·¨·ÃÎÊ£º
ÀýÈ磺
People.java:
public class People { private String name; public People (String aName) { name = aName; } public String getName () { return name; } }
ÔÚTest.javaÖУ¬Èç¹ûÎÒÃÇÊÔͼֱ½Óͨ¹ýPeopleµÄʵÀý¶ÔÏó·ÃÎÊname˽ÓбäÁ¿£º
¡¡