It is a
template that describe the state and behaviour.
It is a blueprint of object
Example:
Class
{
Fields
Methods
}
Example:
class Car{
int
speed=0;
int
geer=1;
public
void increasespeed(int newvalue)
{
speed=speed+newvalue; }
Public
void changegeer(int value)
{
geer=value; }
Void
print()
{ system.out.printl(speed);
}
Class Test
{
Public
static void main(String args[])
{ Car
c1=new Car();
Car c2=new
Car();
C1.increasespeed(10);
C2.changegeer(3)
C1.print();
C2.print();
}}
- The class name always should start with capital letter.
- there should not be any space between two word but you can use the underscore.
- Java file name and class name should be same.
- public class HelloWorldApp {
public static void main(String[] args) {
// Display "Hello World!"
System.out.println("Hello World!");
}
}
- output:
- Hello World!
No comments:
Post a Comment