Why are some constants public and other private in an Android library code -
problem
why constants under public
modifier while other private
? under public
can called applications use library? if so, how call constant app, this: certainlibraryclass.activityresultcode.code_a
?
code
public class certainlibraryclass { public class activityresultcode { public static final int code_a = 0x02; public static final int code_b = 0x03; public static final int code_c = 0x04; } public class versioncode { private static final int version_major = 1; private static final int version_minor1 = 0; private static final int version_minor2 = 2; } // .... }
why constants under public
modifier?
ans: other classes can access e.g.result_ok
,success
.
why constants under private
modifier?
ans:so class can access it
e.g. consider calling getid()
libarary function class
public class certainlibraryclass { private static int id=0; public static int getid() { return id+1; }
here not accessing id
field directly ,instead calling getid()
function returns id, means id
variable internally used certainlibraryclass
class
Comments
Post a Comment