Getters & Setters in Hindi

C++ In Hindi – C++ Getters & Setters in Hindi

C++

C++ Getters & Setters in Hindi :- Encapsulation ka sabse mul purpose ye hai ki object ke internal data ko keval usi class ka koi object instance , directly access kar sakte | isliye Class Ke Sabhi Data Members Private Keyword Ke Sath Private Access Mai Define Kiya Jata Hai |

Isliye Yadi Koi Caller , Object Ki State mai Change karna chahta hai, to use indrirectly ka ek public Method ko istekal karke object ki state mai change karna padta hai | Isi ko Ham kuch Example Ke Sath Understand Karte Hai |

C++ Getters and Setters in Hindi

Contents

C++ Getters and Setters Hamare Data ko protect karte hai or inhe ham jyadar jab istemal karte hai jab class ko banate hai | Har Ek Variable ke liye getter & get Method value return karta hai or setter & set method variable ki value ko set karta hai |

Example:

public class Vehicle {
  private String color;
  
  // Getter
  public String getColor() {
  return color;
  }
  
  // Setter
  public void setColor(String c) {
  this.color = c;
  }
}

Getter Method Attribute Value ko Returns karta hai and setter method ek parameter leta hai or attribute ko value assigns karta hai.

Getters & Setters in Hindi

Getter And Setter ko ab Ham Defined Karte Hai or use ham main program mai istemal karte hai |

public stativ void main(String[] args) {
  Vehicle v1 = new Vehicle();
  v1.setColor("Red");
  System.out.println(v1.getColor());
}

// Outputs "Red"

Getter And Setter Allow karta hai Hamare Value Ko Control Karne ke liye |

Why getter and setter in Hindi?

Getter And Setter Se Programmer Control Kar Sakta hai important variables ko accessed or updated karne mai or Variable ki Value ko change kar sakta hai wo bhi koi specified range tak |

Leave a Reply

Your email address will not be published. Required fields are marked *