Ana 的个人资料Ana Eva's Blog照片日志列表 工具 帮助

日志


2月1日

And like a true geek...

Can't sleep? Pick up a programming book and start reading it.

I have been wanting to pick up on C# for some time now. So, as I was sitting here, after writing my preivous entry, I looked at my bookshelf and thought, why don't I start refreshing up my mind with programming. That way I treated my mind as if it was a child who suffers from hyperactivity; I tried to channel the energy into something useful.

So, I started reading the basics of C#, which includes basics of object-orienting. I actually came up with a couple of questions which I was hoping you can help me answer.

  1. A read-only field is similar to a const field. The difference between them is that a read-only can be optionally marked as static while a const is a or behaves like a static field. Now, my question is, a read-only field is good when you want to have the same constant field in different objects of the same class with different values in them? For example, the read-only field age of the objects Tom and Lulu of the class Cat. I can put Tom's age as 7 while Lulu's age as 9? Where if age was a const field, the age would have to be 7 or 9 for both?
  2. Can Java pass values by reference? And if so, how?
  3. Is using out as a parameter modifier a bad perfomance habit if used often since it places an extra burden on the called method because the compiler has to make sure a value was assigned to the variable? Is this a performance issue during compile time or run time? Should I opt for using ref instead whenever possible?
  4. Regarding constructor initializers; the base class and the subclass have to have the same name of the variable of the parameter in the constructor? For example,

class Laptop: Computer    

{

public Laptop(string Brand): base(Brand)

{

int numOfUSBPorts = 4;

string brandName = Brand;

}

}        

  Here, if Brand wasn't passed to base, but instead, a string called TypeOfComputer, it will be an error because the constructor initializer doesn't know where to get TypeOfComputer from? Another thing is that Brand will be used first in the base constructor (so, Brand of the base class will be used to initialized a base variable first) and then Brand of the subclass will be used to initialize brandName?        

Let's see if I can keep up with the programming lessons. Now, let's see if I can finally get some sleep...