|
Originally Posted by ashlee
hi,
Answers are as under
1.Object-oriented programming uses objects and classes. Define what are classes and what are objects? What is the relationship between classes and objects?
A- In the real world, you often have many objects of the same kind. For example, your bicycle is just one of many bicycles in the world. Using object-oriented terminology, we say that your bicycle object is an instance of the class of objects known as bicycles. Bicycles have some state (current gear, current cadence, two wheels) and behavior (change gears, brake) in common. However, each bicycle's state is independent of and can be different from that of other bicycles
Objects are key to understanding object-oriented technology. You can look around you now and see many examples of real-world objects: your dog, your desk, your television set, your bicycle.
Real-world objects share two characteristics: They all have state and behavior. For example, dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles have state (current gear, current pedal cadence, two wheels, number of gears) and behavior (braking, accelerating, slowing down, changing gears).
relationship-The has-a relationship means that one type of object contains another or is composed of another. Some examples are: a car has-an engine, a bicycle has-a wheel, and a coffee cup has coffee
The is-a relationship means that one type of object is a more specific version of a general type. Some examples are: a car is-a vehicle, a bicycle is-a vehicle, and a coffee cup is-a cup.
The uses-a relationship means that during some activity, one type of object uses another type of object. Some examples are: a car uses-a squeegee (during a window-washing activity), a bicycle uses-a pump (during a tire-pumping activity), and a coffee cup uses-a stirrer (during a stirring activity).
2."null" is not a keyword, but a special literal of the null type. It can be cast to any reference type, but not to any primitive type such as int or boolean. The null literal doesn't necessarily have value zero. And it is impossible to cast to the null type or declare a variable of this type
3.A constructor is executed when an object is instantiated from a class .It is possible to take initial parameters (like the initial mileage in our example) and to initialize the variables of the newly created object. Constructors are declared like other methods but use the name of the class . The parameter follow the name of a method and are enclosed in parentheses (even if there are no parameters).
Use-Constructors have one purpose in life: to create an instance of a class. This can also be called creating an object, as in:
Platypus p1 = new Platypus();
The purpose of methods, by contrast, is much more general. A method's basic function is to execute Java code.
rest answers i will give you in short span time...
Thanks
ashlee
|