![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
![]() |

|
| Programming tutorials All Knowledge Info and links to posted here |
![]() |
|
Object Oriented Programming in Java
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Administrator
Posts: 18,715
Join Date: Jan 2006
Rep Power: 10
IM:
|
The form for a class is public class ClassName { //start of class code private int varibleOne; //variable one public int variableTwo; //variable two public ClassName(Object parameter) //Constructor {//contstuctor start }//constructor end public void methodName(Object parameter, int parameterTwo) //Function { //start of method } //end of method }//end of class code Any class, constructor, function is started and and ended by brackets { } The constructors and methods can have parameters. Parameters are the stuff in the ( ). Public refers to classes, methods and constructors that other class can reference (only methods should really be private). Private are methods only a method can access. Parameters are information given to a constructor or function that can allow it to do a function to. Now it is not necessary to give a parameter, in which case just leave blank () or to do anything with the parameter. public class Adding { private int storedNumber; public Adding(int number) { storedNumber = number; } public void addToStored(int newNumber) { storedNumber = storedNumber + newNumber; } } The 'number' parameter given to the Adding constructor when an object of Adding is created is stored in the variable for the class 'storedNumber'. Once the constructor has finished executing, the 'number' variable is lost. This is true for a parameter or local variable. So a way to think about it... a variable only lasts inside its brackets. The method takes the variable storedNumber and an integer parameter given, adds them together and stores them inside the 'storedNumber'. So when you create an object of a class, you have variables that hold information and function to do things. So you could have two objects of the class: Adding and then be able to call functions of the two object. The functions will do the same function but you could change the numbers and information. |
|
|
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Windows Vista : Programming Indigo: The Programming Model | Anilrgowda | Microsoft windows vista error | 0 | 07-Feb-2007 10:23 PM |
| The Javalog.txt file is created in the Windows\Java folder when Java logging is enabl | Anilrgowda | Microsoft windows vista error | 0 | 29-Jan-2007 10:09 AM |
| Yahoo Publisher Network (YPN), Adsense, And Other PPC Oriented Websites. Where To Sta | Anilrgowda | Publisher Network | 0 | 29-Dec-2006 01:27 AM |
| Windows Vista : Programming Indigo: The Programming Model | Anilrgowda | Microsoft windows vista error | 0 | 23-Dec-2006 10:06 PM |
| SEO Writing Strategies for Graphic-Oriented Sites | Anilrgowda | Search Engine Optimization | 0 | 22-Dec-2006 02:31 AM |