Answer to Question #3475 in Java | JSP | JSF for Y mukundareddy
(1) Write a program to declare any variables as public and access them in another class as you seen in the examples?
1
2011-08-07T07:13:53-0400
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;
}
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
JavaJSPJSF
Comments
Leave a comment