Public vs private instance fields
From: Brian Munroe (brian.e.munroe_at_gmail.com)
Date: 03/29/05
- Next message: Big Jim: "Re: Troubles with my classpath"
- Previous message: Tom Vercauteren via JavaKB.com: "Re: Troubles with my classpath"
- Next in thread: Bryce: "Re: Public vs private instance fields"
- Reply: Bryce: "Re: Public vs private instance fields"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Mar 2005 11:19:22 -0800
Newbie Java/OOP question here, which is more correct?
1) Define a public instance field and access it like:
Object o = new Object()
o.field1 = "hello";
System.out.println(o.field1);
2) Define a private instance field and use set/get methods to access
it:
Object o = new Object()
o.setField1("hello");
System.out.println(o.getField1());
I prefer to make it public, less typing all around, but being my luck,
it isn't the correct way either :)
thanks
-- brian
- Next message: Big Jim: "Re: Troubles with my classpath"
- Previous message: Tom Vercauteren via JavaKB.com: "Re: Troubles with my classpath"
- Next in thread: Bryce: "Re: Public vs private instance fields"
- Reply: Bryce: "Re: Public vs private instance fields"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|