- Class is a key-word, It is a user-defined function.
- Every java program one class and one main methods.
Public Class MyClass
{
public static void main(string[] args)
{
int a=10;
int b=20;
int c=a+b;
System.out.println(“Answer=”c);
}
}
Class Constructor
- Class Constructor name is same as class name.
- It is a member method,never return any value define multiple constructor.
Main Class–
Public Class MyClass
{
public static void main(string[] args)
{
Cube cube1=new cube();
}
}
public class Cube
{
int length;
int breath;
int height;
public int get cube volume()
{
return( length* breath*height);
}
Cube() //Constructor—> This is same class name
{
System.out.println(“Welcome CastorClasses”);
}
0 Comments:
Post a Comment