(2) Write a program to declare any variables as private in the same class and access them in the same class?
1
Expert's answer
2011-08-07T07:15:24-0400
public class Task5 { public static void main(String[] args) { & Rectangle r1 = new Rectangle(5, 10); & r1.printInfo(); } }
// Class with private members. The function printInfo() of the same class // has access to this members class Rectangle { // These variables are private, so we can access them only in the same class private int width; private int height;
Comments
Leave a comment