Thursday, April 25, 2019

Java Research Paper Example | Topics and Well Written Essays - 1750 words

Java - enquiry Paper ExampleMembers declared public have no bounds, they brook be chafeed from anywhere by any class irrespective of whether they are in same package or not. To sum up, the access limits of each modifier are tabulated below Members declared as Can be accessed from members of Same partitioning Same Package Subclass Other Packages Public Yes Yes Yes Yes Private Yes No No No Protected Yes Yes Yes No b) Span of access Variable that are declared orphic/protected can be accessed external its scope by defining set and get regularitys for that multivariate in the declaring class and calling the method from immaterial. However, the set and get methods must be declared public. Alternatively, we can use Reflection API which provides pre-defined methods to access private members of other classes. Still private members of super class cannot be accessed through these methods. c) Example 2. Passing literary arguments to methods a) Parameter handling by methods In java, we c an pass lines of any valid information type to methods. This includes both(prenominal) primitive info types like integer, string, float etc and reference data types like intents and arrays. In both the cases, the data is passed only by value and not by reference, which means only a copy of the unsettled is sent and this will not affect the original value of the variable in the internal memory. i. changing value of a primitive-type parameter within a method When the value of the primitive type parameter is changed within the method, it remains in effects only within the scope of the function (method). It is not reflected to the outside world and the passed variable still contains its original value, unless until we assign this returned value to the variable. ii. Changing value of a primitive-type data field of a reference-type When the value of object fields of a reference type is changed within the method, it can be reflected in the original objects field provided it has the proper access level. However, the reference variable will still point to the same object. iii. Reassigning the reference of a reference-type parameter to a spick-and-span object that you create within a method In this case, the reference variable will point to the virgin object. b) Example In the above example, only the fields modified inside the method is reflected outside in the reference variable. The actual reference object is not modified outside when it is assigned a new object inside the method. For this reason, the textObject2 is not modified. However, in the next line when the reference variable is assigned a new object returned from the method, it now points to the new object. 3. Static Modifier a) Using the modifier static on a variable A variable is declared static in order to make it fond commonly among all the instances of a class. In other words, the actual variable can be straight off accessed and modified from any objects/instance of a class, just like a common shared cusp in a network system. This type of variable is frequently employed in situation where all(prenominal) instances of a class require a common variable to update or retrieve trustworthy information which is common to all users of the application. For example, retrieving or updating the most frequently viewed products in an online shopping application. Further, static variables are employed in combination with public and final keyword to store values that remain uninterrupted throughout the application.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.