Lab 4
Lab 4
AIM (a): WAP that creates a class circle with instance variables for the centre and the radius. Initialize
and display its variables.
SOURCE CODE:
}
OUTPUT (a):
AIM (b): Modify experiment 1 to have a constructor in class circle to initialize its variables.
SOURCE CODE:
public circleclass()
{
System.out.println("CONSTRUCTOR CALLED");
x=9;
y=9;
radius=7;
}
SOURCE CODE:
public circleclass()
{
System.out.println("CONSTRUCTOR 1 CALLED");
x=9;
y=9;
radius=7;
}
}
OUTPUT (c):
AIM (d): Write a program to display the use of this keyword.
SOURCE CODE:
SOURCE CODE:
}
}
OUTPUT (e):
AIM (f): Write a Java Program to get the cube of a given number using the static method.
SOURCE CODE:
import java.util.Scanner;
public class static_cube {
float number;
Scanner s=new Scanner(System.in);
System.out.print("ENTER THE NUMBER:");
number=s.nextInt();
cube(number);
}
}
OUTPUT (f):
AIM (g): Write a program that describes a class person. It should have instance variables to record name,
age and salary. Create a person object. Set and display its instance variables.
SOURCE CODE:
String name;
int age;
float salary;
}
OUTPUT (g):