Results 1 to 4 of 4

Thread: Scope of Object or variable in Object oriented Programming Languages

  1. #1
    Join Date
    Dec 2010
    Posts
    16

    Scope of Object or variable in Object oriented Programming Languages

    Hey Friends, I wanted to know about the scope of object and variable in object oriented programming languages. In my college I was not able to understand this term which I think is very much important to understand. This term is in other object oriented languages. So, anybody who is aware of the above solution please let me know as soon as possible. It would be better if the term is explained with proper example.

  2. #2
    Join Date
    Apr 2009
    Posts
    569

    Re: Scope of Object or variable in Object oriented Programming Languages

    Scope is the largest region of program text in which an object or variable can be potentially used in the program. The scope of a variable or object is nothing but its visibility in the program. It is the mechanism by which it is possible to limit the visibility of an object or variable in a program. Once the scope of an object ends the visibility of the object also ends and the object is destroyed by the C++ and memory is recollected from the object.

  3. #3
    Join Date
    Apr 2009
    Posts
    488

    Re: Scope of Object or variable in Object oriented Programming Languages

    For example
    #include<iostram.h>
    Line 1 main()
    Line 2 {
    Line 3 Box b1;
    Line 4 {
    Line 5 Box b2;
    Line 6 }
    Line 7 {
    Line 8 Box b3;
    Line 9 }
    Line 10 }

    Just observe the above program, The object b1 is created at line 3 so its scope will be throughout the program (up to line 10),The object b2 is created at line no 5 and it is in the curly brace which starts from line no 4 and ends at line no 6.So scope of b2 will be only in between line no 4 -6.As soon as the control of program will come out of line no 6 the object b2 will be destroyed by C++ as its scope ends. The same thing will happen with object b3.The scope of object b1 will end at line no.10.

  4. #4
    Join Date
    May 2009
    Posts
    527

    Re: Scope of Object or variable in Object oriented Programming Languages

    Well you should that in object oriented programming languages once the object are destroyed then the scope of its object is also destroyed. Then that object won’t be available in the program. Scope of object or variable can said as lifetime of an object or variable. So, one should know that once the object or variable is destroyed then it access and visibility is also over.

Similar Threads

  1. Object oriented programming with java
    By cloud101 in forum Software Development
    Replies: 2
    Last Post: 22-02-2012, 01:11 AM
  2. Replies: 4
    Last Post: 11-07-2011, 02:39 PM
  3. Replies: 3
    Last Post: 08-01-2011, 06:23 AM
  4. static methods in object oriented programming
    By Satchel in forum Software Development
    Replies: 5
    Last Post: 07-01-2011, 09:58 PM
  5. The OOP Object Oriented programming Concept & its principle?
    By Bhavya in forum Software Development
    Replies: 3
    Last Post: 25-02-2009, 09:16 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,814,053.46578 seconds with 17 queries