Class is a collection of similar objects. Which have common properties.
Syntax
class class_name
{
//member functions and variables.
}
{
//member functions and variables.
}
How to create a objects for class
class_name c=new class_name;
We can access the member variable and member methods using dot operator.
c.member_function();
Eg:
class bike
{
void fun()
{
System.out.println("member method");
}
public static void main(String[] args)
{
bike B=new bike();
B.fun();
}
}
class bike
{
void fun()
{
System.out.println("member method");
}
public static void main(String[] args)
{
bike B=new bike();
B.fun();
}
}
output
member method
member method
Comments
Post a Comment