Difference between public member and private member of a class in Java?

A public member may be accessed by any class. A private member may only be accessed by the class in which it is contained Example: class A contains both a public int and a private int class A { public int publicNumber = 0 private int privateNumber = 0 } class B will attempt to access the members of A class B { void f() { Create a new instance of A A a = new A() Try to print out each member System.out. Println(a.

PublicNumber) System.out. Println(a. PrivateNumber) } } If you put each of these classes in a separate file and attempted to compile them, you would get an error informing you that 'privateNumber has private access in A.

Member functions (methods). Public variables, are variables that are visible to all classes. Which they belong.

Which they belong, and any subclasses. Actually needs direct access to the information. We have declared our string and integer to be public.

Us a negative balance). We wrote code in our constructor to prevent negative balances. Balance private or proteced.

Can't put invalid data in.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions