A method is a set of program statements that is the fundamental unit of execution in Java. Every method every method exists as part of a class. The two main reasons for a method are to organize the program and make the code for the program reusable. A Java program is a set of one or more classes and every class contains a set of one or more methods. Methods provide the logic that constitutes the behavior defined by a class. All applications must have the method "main()" When a program is being executed methods can invoke other methods in the same or different class. Methods cannot exist outside of classes and program codes cannot exist outside of a method. Method names begin with lowercase letters and class name begin with capital letters. This is how to distinguish between the two. A static method is related to a class. This means that it is not necessary to create an instance of that class to be able to use a static method. An example of a static method is "static float abs(float f)" This method returns the absolute value of f. This method is part of the Math class. Another type of method is the instance method. An instance method deals with an object. Since this method deals with an object it is
Inheritance is used with classes because each of the subclasses to each class will inherit all the traits and methods of its superclass. Inheritance works with encapsulation when a private class creates another private subclass. All of the private classes that are created will inherit all the traits of its superclass. This will make it easier to control access to important data. Also it will keep all the subclasses of a private class private. For example class pen has public attributes of pull cap and twist cap. From there a subclass is created called marker. This class will also have the public attributes of pull cap and twist cap. The use inheritance, class and encapsulation make it easier and less time consuming to write programs.
Encapsulation groups data with the code that is used to manipulate that data. Direct access to the data from any other software is not permitted. The first benefit is that it is easier to change the type of data that is used. For example if the proper access methods are used then it is much easier to change the type of data. The second benefit is that it makes it easier to control access to sensitive data. It does this by grouping data into two different groups. The first group is the private group. The people i
All papers and essays are for research and reference purposes only!
Copyright 2002-2009
Direct Essays , LLC. All Rights Reserved. DMCA Webmasters make $$$$