1 / 4

Are They Accessible?

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 {

kelly-rojas
Download Presentation

Are They Accessible?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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? • } • }

  2. Employee Example • firstName • lastName • socialSecurityNumber • grossSales • commissionRate • earnings() • toString() CommissionEmployee • baseSalary • earnings() • toString() BasePlusCommissionEmployee

  3. Shapes Example

  4. 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; }

More Related