--%>

"this" pointer is different from a pointer to an object

Q. What is "this" pointer? Explain how is this is different from a pointer to an object?

 

Ans. This: This is variable that refers to the object that has called the member function. This variable is available in all the methods of the class. This is created automatically so we do not need to decide this variable.

 

Example

Class memory

{

Private Int rs;

Private Int paisa;

Public void set (int rs, Int paisa)

{

This. rs = rs;

This . paisa = paisa;

}

Public void set (Int rs, Int paisa)

{

Rs = rs;

Paisa = paisa;

}

*/

Note: If we comment out this x has been and put restriction on code y to execute, there will be default value in the field. if we create an object of this money class outside the money then, this pointer exists in that particular class only and a pointer to an object can exist in outside classes also. 

   Related Questions in Programming Languages

  • Q : Explain Branch instruction Branch

    Branch instruction: It stores a new instruction address into the program counter. The consequence of this is the next instruction to be fetched will not generally be the one instantly following the branch instruction. Therefore the normal chronologica

  • Q : What are ORB-IOR-a servant-a POA manager

    In CORBA, what are i) an ORB ii) an IOR iii) a servant iv) a POA and v) a POA manager?

  • Q : Describe Unnamed package Unnamed

    Unnamed package: All classes defined in the files without a package declaration are placed in an unnamed package.

  • Q : Explain Relative filename Relative

    Relative filename: It is a filename whose full path is associative to some point within a file system tree-frequently the present working folder (that is, directory). For example:   

  • Q : What is an Exception Exception : An

    Exception: An object symbolizing the occurrence of an exceptional circumstance - usually, something which has gone wrong in the smooth running of a program. Exception objects are made from classes which expand the Throwable class.

  • Q : Explain Fully qualified class name

    Fully qualified class name: The name of a class, comprising any package name and including class name. The class outline is as follows:     package oddments;    class Outer

  • Q : What is Pointer Arithmetic Pointer

    Pointer Arithmetic: C and C++ provide the ability to modify a pointer’s target address with arithmetic operations. This is used, for example, to index arrays. MyObject* P = ...

    Q : Why is Java pure object oriented

    Explain the reasons that Java is pure object oriented programming language.

  • Q : What is an Operator Operator : It is a

    Operator: It is a symbol, like -, = or ?: taking one, two or three operands and yielding an outcome. The operators are employed in both arithmetic and Boolean expressions.

  • Q : Explain Window manager Window manager :

    Window manager: This is a window manager which provides a computer user with a virtual desktop having one or more windows and working regions in which individual programs might be run. Window managers permit the contents of a user's desktop to be arra