{"id":20,"date":"2010-08-20T05:10:14","date_gmt":"2010-08-20T05:10:14","guid":{"rendered":"http:\/\/nvntung.wordpress.com\/?p=20"},"modified":"2013-12-18T15:17:28","modified_gmt":"2013-12-18T14:17:28","slug":"phuong-thuc-static-class-va-instance","status":"publish","type":"post","link":"https:\/\/www.itersdesktop.com\/fr\/2010\/08\/20\/phuong-thuc-static-class-va-instance\/","title":{"rendered":"Ph\u01b0\u01a1ng th\u1ee9c static (class) v\u00e0\u00a0instance"},"content":{"rendered":"<p>Ti\u1ebfp theo b\u00e0i gi\u1edbi thi\u1ec7u v\u1ec1 Overloading v\u00e0 Overriding, t\u00f4i mu\u1ed1n t\u00f3m l\u1ea1i s\u1ef1 kh\u00e1c bi\u1ec7t c\u0169ng nh\u01b0 \u0111i\u1ec3m l\u01b0u \u00fd c\u1ee7a c\u00e1c ph\u01b0\u01a1ng th\u1ee9c l\u1edbp (ph\u01b0\u01a1ng th\u1ee9c t\u0129nh) v\u00e0 ph\u01b0\u01a1ng th\u1ee9c instance. \u0110\u00e2y l\u00e0 hai ki\u1ec3u ph\u01b0\u01a1ng th\u1ee9c s\u1eed d\u1ee5ng ph\u1ed5 bi\u1ebfn trong l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng<\/p>\n<p>Ph\u01b0\u01a1ng th\u1ee9c l\u1edbp (t\u0129nh) (Static Methods): l\u00e0 ph\u01b0\u01a1ng th\u1ee9c \u0111\u01b0\u1ee3c g\u1ecdi th\u00f4ng qua t\u00ean l\u1edbp. Trong qu\u00e1 tr\u00ecnh c\u00e0i \u0111\u1eb7t ph\u01b0\u01a1ng th\u1ee9c ch\u00fang ta d\u00f9ng t\u1eeb kh\u00f3a static.<\/p>\n<p>Xem v\u00ed d\u1ee5:<\/p>\n<pre>class MyUtils {\r\n    . . .\r\n    \/\/================================================= mean\r\n    public static double mean(int[] p) {\r\n        int sum = 0;  \/\/ sum of all the elements\r\n        for (int i=0; i&lt;p.length; i++) {\r\n            sum += p[i];\r\n        }\r\n        return ((double)sum) \/ p.length;\r\n    }\/\/endmethod mean\r\n    . . .\r\n}\r\n<\/pre>\n<p>Mu\u1ed1n g\u1ecdi ph\u01b0\u01a1ng th\u1ee9c n\u00e0y b\u00ean trong l\u1edbp m\u00f4 t\u1ea3 n\u00f3, ch\u00fang ta ch\u1ec9 c\u1ea7n s\u1eed d\u1ee5ng t\u00ean ph\u01b0\u01a1ng th\u1ee9c: mean(). Tuy nhi\u00ean, n\u1ebfu g\u1ecdi ph\u01b0\u01a1ng th\u1ee9c b\u00ean ngo\u00e0i l\u1edbp ch\u00fang ta ph\u1ea3i k\u00e8m theo t\u00ean l\u1edbp; ngh\u0129a l\u00e0: MyUtils.mean().<\/p>\n<p>Ph\u01b0\u01a1ng th\u1ee9c instance: k\u1ebft h\u1ee3p v\u1edbi m\u1ed9t object v\u00e0 c\u00e1c bi\u1ebfn instance c\u1ee7a object \u0111\u00f3.<\/p>\n<p>V\u00ed d\u1ee5:<\/p>\n<pre>\/\/ File   : dialog\/capitalize\/Capitalize2.java\r\n\/\/ Purpose: Capitalize first letter of each name.  Declare with first use.\r\n\/\/ Author : Fred Swartz - placed in public domain.\r\n\/\/ Date   : 30 Mar 2006\r\n\r\nimport javax.swing.*;\r\n\r\npublic class Capitalize2 {\r\n\r\n    public static void main(String[] args) {\r\n        \/\/.. Input a word\r\n        String inputWord = JOptionPane.showInputDialog(null, \"Enter a word\");\r\n\r\n        \/\/.. Process - Separate word into parts, change case, put together.\r\n        String firstLetter = inputWord.substring(0,1);  \/\/ Get first letter\r\n        String remainder   = inputWord.substring(1);    \/\/ Get remainder of word.\r\n        String capitalized = firstLetter.toUpperCase() + remainder.toLowerCase();\r\n\r\n        \/\/.. Output the result.\r\n        JOptionPane.showMessageDialog(null, capitalized);\r\n    }\r\n}\r\n<\/pre>\n<p>C\u00e1c ph\u01b0\u01a1ng th\u1ee9c: substring, toUpperCase, toLowerCase l\u00e0 c\u00e1c ph\u01b0\u01a1ng th\u1ee9c instance. C\u00e1c ph\u01b0\u01a1ng th\u1ee9c showInputDialog, showMessageDialog l\u00e0 c\u00e1c ph\u01b0\u01a1ng th\u1ee9c l\u1edbp.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ti\u1ebfp theo b\u00e0i gi\u1edbi thi\u1ec7u v\u1ec1 Overloading v\u00e0 Overriding, t\u00f4i mu\u1ed1n t\u00f3m l\u1ea1i s\u1ef1 kh\u00e1c bi\u1ec7t c\u0169ng nh\u01b0 \u0111i\u1ec3m l\u01b0u \u00fd c\u1ee7a c\u00e1c ph\u01b0\u01a1ng th\u1ee9c l\u1edbp (ph\u01b0\u01a1ng th\u1ee9c t\u0129nh) v\u00e0&hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[49,71,101],"class_list":["post-20","post","type-post","status-publish","format-standard","hentry","category-lap-trinh-huong-doi-tuong","tag-class","tag-instance","tag-static"],"_links":{"self":[{"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":1,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":1135,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/posts\/20\/revisions\/1135"}],"wp:attachment":[{"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}