(1) Write a program to declare any variables as public and access them in another class as you seen in the examples?
public class Task6
{
public static void main(String[] args)
{
& Rectangle r1 = new Rectangle(5, 10);
& // The access to the public variables
& System.out.print("Rectangle: width = " + r1.width + ", height = " + r1.height);
}
}
class Rectangle
{
// These variables are public so we can access them anywhere
public int width;
public int height;
Rectangle(int pWidth, int pHeight)
{
& width = pWidth;
& height = pHeight;
}
}