Monday, January 24, 2011

CS 11: Research about constructors and objects

A constructor is a function which is used to initialize the variables in a program before the creation of object.
An object is an instance of a class.

Research  and post as comment.
Every one must post some thing.
Points : 2(1 for each)

by: Friday, 28 Jan 2011.

7 comments:

  1. constructor :
    In object-oriented programming, a constructor (sometimes shortened to ctor) in a class is a special type of subroutine called at the creation of an object. It prepares the new object for use, often accepting parameters which the constructor uses to set any member variables required when the object is first created.

    source :http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming)

    object :
    an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure

    source : http://en.wikipedia.org/wiki/Object_(computer_science)

    ReplyDelete
  2. Object:
    An object is an instance of a class created using a new operator. The new operator returns a reference to a new instance of a class. This reference can be assigned to a reference variable of the class. The process of creating objects from a class is called instantiation. An object encapsulates state and behavior.
    An object reference provides a handle to an object that is created and stored in memory. In Java, objects can only be manipulated via references, which can be stored in variables.
    Creating variables of your class type is similar to creating variables of primitive data types, such as integer or float. Each time you create an object, a new set of instance variables comes into existence which defines the characteristics of that object. If you want to create an object of the class and have the reference variable associated with this object, you must also allocate memory for the object by using the new operator. This process is called instantiating an object or creating an object instance.
    When you create a new object, you use the new operator to instantiate the object. The new operator returns the location of the object which you assign to a reference type.
    Constructor:
    A java constructor has the same name as the name of the class to which it belongs. Constructor’s syntax does not include a return type, since constructors never return a value.
    Constructors may include parameters of various types. When the constructor is invoked using the new operator, the types must match those that are specified in the constructor definition.
    Java provides a default constructor which takes no arguments and performs no special actions or initializations, when no explicit constructors are provided.
    The only action taken by the implicit default constructor is to call the superclass constructor using the super() call. Constructor arguments provide you with a way to provide parameters for the initialization of an object.

    ReplyDelete
  3. Here's two:
    - Constructors have no return type
    - Constructors have the same name as their class

    ReplyDelete
  4. the name of constructor and name of the class are same. A constructor creates an Object of the class that it is in by initializing all the instance variables and creating a place in memory to hold the Object.

    ReplyDelete
  5. they form the base of the program and their use reduces the size of programs since they prevent the use of codes repetitively.

    ReplyDelete