Class(name example:HelloWorld)
-reusable modules, create instances, filled with methods, provide your applet with methods
-serve as blueprints for the objects that programmers need to create
1. letters
2. numbers
3. underscores _
4. dollar signs $
5. case-seneitive, start with upper case letters
{
class definition or
a statement of a method ending with ; or
an assignment statement
(ex: x=0; )
(ex: a variable = the value to be put into the variable;)
}
For Example:
public class HelloWorld
{
class definition
}
Instance Variables
-the variables we want each instance to contain, to hold info
3 Types of Methods - usually is data type +method name
- declare a method is like declare a variable and declare a method
-it usually has data type+name
A. Mian Method
public static void main ( String [ ] args ) parameter list/arguments, providing outside info
{
statement1;
statement2;
}
B. Constructor Method
- in this kind of method, the method name is just like the class name
- to bulid a new object from a class
- to give its data elements the values
public HelloWorld (String text) parameter list/arguments, providing outside info
{
statement;
}
C. Method
public void printText () parameter list/arguments, providing outside info
{
statement;
}
void: When a method doesn't need to return a value, the type in its first line will be void.
2 ways of making comments
Type 1: Multi-line comment
/*
*/
Type 2: Single-line comment
//
No comments:
Post a Comment