instance-variables

Does a private @property create an @private instance variable?

吃可爱长大的小学妹 提交于 2019-11-27 07:55:13
I've read that @synthesize will automatically create corresponding instance variables for @property and that ivars are @protected by default. But, what if I use a class extension (like below) to indicate that the @property methods are to be private? // Photo.m @interface Photo () @property (nonatomic, retain) NSMutableData *urlData; @end Will the corresponding ivar then be @private ? Or should I explicitly declare it as @private like so? // Photo.h @interface Photo : Resource { @private NSMutableData *urlData; } @private instance variables are a compile-time-only feature. Given that the

Error: identifier expected in Java

我只是一个虾纸丫 提交于 2019-11-27 07:18:17
问题 I am a new learner of Java. I learned some of the Java core concepts. I got the identifier expected error when run my following code: class Sekar { public static int i,j,k; i = 900; static void max() { j = 100; if(i>j) { k=i; } else { k=j; } System.out.println("The maxmimum vale between"+i+"and"+j+"is :"+k); } public static void main(String[] args) { max(); } } When I compile my code, I get the following error: error: identifier expected i = 900; ^ Can any one explain why this error happens

Why are instance variables in Java always private?

偶尔善良 提交于 2019-11-27 07:17:59
I'm newbie to Java and I'm learning about encapsulation and saw an example where instance variables are declared as private in a class. http://www.tutorialspoint.com/java/java_encapsulation.htm I have 2 queries: Why are instance variables private? Why not public? What if instance variables are made public and accessed directly? Do we see any constraints? Can you explain with an example as to what will go wrong in case the instance variables are declared as public in a class in Java? Thomas Instance variables are made private to force the users of those class to use methods to access them. In

Calling methods on reference variable vs Calling methods on a new object

拜拜、爱过 提交于 2019-11-27 06:56:49
问题 I'm having confusion in calling a non-static method class A { void doThis() {} public static void main(String... arg) { A a1 = new A(); a1.doThis(); // method - 1 new A().doThis(); // method - 2 } } I know that both method-1 and method-2 will call doThis() , but is there any functional difference? 回答1: Is there any functional difference? Both will behave in the same way. The second option doesn't allow you to reuse that instance again. It may be convenient and concise in one-line return

'Use of self in method call before super.init initializes self', can't init properties through a method call

元气小坏坏 提交于 2019-11-27 06:40:20
问题 I'm curious is there is anyway to call a method inside your init method that sets instance properties of the class. Essentially I just have a class that sub-classes UIView, adds some subviews in init, and some of those subviews are instance variables of the class. class MyView: UIView { var collectionView: UICollectionView convenience init () { self.init(frame:CGRectZero) } override init (frame : CGRect) { super.init(frame : frame) addSubviews() } required init(coder aDecoder: NSCoder) {

Java Field Hiding

删除回忆录丶 提交于 2019-11-27 06:22:21
问题 I was wondering what it means to say a field is hidden between 2 java classes and what it means when running code in terms of resulting output? I have an abstract class with a protected static boolean field = false and a sub class which has a boolean field with the same name but is not static and set to true . If I had this code: Superclass d = new subclass(); what would be the value of the boolean field in the superclass and the boolean field in the subclass? Does subclass field stay as

Setting delegate to nil in dealloc

允我心安 提交于 2019-11-27 06:11:23
问题 In Objective-C, I understand that if an object sets itself as the delegate of another object, it should set that object's delegate to nil in its dealloc to avoid getting sent messages after it's gone. However, when using Accessorizer (an Xcode utility), the stub code it generates also puts a delegate = nil in the dealloc of the class that has the delegate instance variable. What is the purpose of that? 回答1: It's a defensive programming move. It's clearing out the reference to the delegate

Passing variables, creating instances, self, The mechanics and usage of classes: need explanation [closed]

微笑、不失礼 提交于 2019-11-27 04:59:22
问题 I've been sitting over this the whole day and Im a little tired already so please excuse me being brief. Im new to python. I just rewrote a working program, into a bunch of functions in a class and everything messed up. I dont know if it's me but I'm very surprised I couldn't find a beginner's tutorial on how to handle classes on the web so I have a few questions. First of all, in the __init__ section of the class I have declared a bunch of variables with self.variable=something . Is it

Java Instance Variables vs Local Variables

三世轮回 提交于 2019-11-27 03:46:12
I'm in my first programming class in high school. We're doing our end of the first semester project. This project only involves one class, but many methods. My question is best practice with instance variables and local variables. It seems that it would be much easier for me to code using almost only instance variables. But I'm not sure if this is how I should be doing it or if I should be using local variables more (I would just have to have methods take in the values of local variables a lot more). My reasoning for this is also because a lot of times I'll want to have a method return two or

ruby: class instance variables vs instance variables

半世苍凉 提交于 2019-11-27 02:06:55
my idea is to create a community wiki for people that come from a java background because reading a lot of explanations, I couldn't comprehend anything until I actually tried a couple of things and the pieces of the puzzle started to find their places. But I first need to make sure I'm getting it right. Coming from such background it was very confusing for me to find out that @variable may mean 2 very different things. Here is an example: class Test @ins = "gah" def self.ins puts @ins end def initialize() @ins = "wtf?" end def ins2 puts @ins end end As far as I understand, the first @ins is an