{"id":686,"date":"2013-01-23T04:35:40","date_gmt":"2013-01-23T04:35:40","guid":{"rendered":"http:\/\/codeatelier.wordpress.com\/?p=452"},"modified":"2013-01-23T04:35:40","modified_gmt":"2013-01-23T04:35:40","slug":"static-call-from-one-package-to-another","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/static-call-from-one-package-to-another\/","title":{"rendered":"Static call from one package to another"},"content":{"rendered":"<pre>\npackage packA;\n\npublic class sam1 \n{\n public static final double DIAMETER = 12756.32; \/\/ kilometers\n \n public static void hithere()\n {\n\t System.out.println(\"Hi There\");\n } \n}\n\n\npackage packB;\nimport packA.sam1;\n\npublic class sam2 \n{\n\tpublic static void main(String args[])\n\t{\n\t\tsam2 objsam2 = new sam2();\n\t\tobjsam2.halfway();\t\t\n\t}\n\t\n\tpublic void halfway()\n\t{ \n\t\tsam1.hithere();\n\t\tSystem.out.println(sam1.DIAMETER\/2.0);\n\t}\n}\n\n<\/pre>\n<p>-Two Packages \u2013 packA and  packB \u2013 While importing static from packA to packB you should either use import packA.sam1; or  import static packA.sam1.*;<\/p>\n<p>Using import static packA.sam1; will not allow to access elements in package<\/p>\n<p>If you use import packA.sam1;<br \/>\nclassName.StaticVariableName<\/p>\n<p>If you use import static packA.sam1.*;<br \/>\nStaticVariableName<\/p>\n","protected":false},"excerpt":{"rendered":"<p>package packA; public class sam1 { public static final double DIAMETER = 12756.32; \/\/ kilometers public static void hithere() { System.out.println(&#8220;Hi There&#8221;); } } package packB; import packA.sam1; public class sam2 { public static void main(String args[]) { sam2 objsam2 = new sam2(); objsam2.halfway(); } public void halfway() { sam1.hithere(); System.out.println(sam1.DIAMETER\/2.0); } } -Two Packages&hellip; <a href=\"https:\/\/codethataint.com\/blog\/static-call-from-one-package-to-another\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[104],"tags":[],"class_list":["post-686","post","type-post","status-publish","format-standard","hentry","category-static-and-final"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/686","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=686"}],"version-history":[{"count":0,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/686\/revisions"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=686"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=686"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=686"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}