40 likes | 149 Views
Are They Accessible?. class B { private int a; protected int b; public int c; public void bbb() { System.out.printf(“%d<br>”, a ); // accessible? System.out.printf(“%d<br>”, b ); // accessible? System.out.printf(“%d<br>”, c ); // accessible? } } class A extends B {
E N D
Are They Accessible? • class B { • private int a; • protected int b; • public int c; • public void bbb() { • System.out.printf(“%d\n”, a); // accessible? • System.out.printf(“%d\n”, b); // accessible? • System.out.printf(“%d\n”, c); // accessible? • } • } • class A extends B { • public void bbb(int a) { • Ssystem.out.printf(“%d\n”, this.a); // accessible? • System.out.printf(“%d\n”, a); // accessible? • System.out.printf(“%d\n”, b); // accessible? • System.out.printf(“%d\n”, c); // accessible? • } • } • class C { • public void ccc() { • B b=new B(); • System.out.printf(“%d\n”, b.a); // accessible? • System.out.printf(“%d\n”, b.b); // accessible? • System.out.printf(“%d\n”, b.c); // accessible? • } • }
Employee Example • firstName • lastName • socialSecurityNumber • grossSales • commissionRate • earnings() • toString() CommissionEmployee • baseSalary • earnings() • toString() BasePlusCommissionEmployee
Class Rectangle class MyRectangle { // constructors public MyRectangle(int l, int r, int t, int b) { left=l; right=r; top=t; bottom=b; } // functions public int area() { return (right-left)*(bottom-top); } public int perimeter() { return 2*(right-left+bottom-top); } public boolean contains(int x, int y) { return (x>=left && x<right && y>=top && y<bottom); } // data members private int left, right, top, bottom; }