Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

encapsulation in java

public class Person {

    private String name;
    private int age;

    public  void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }
}
//parent class
public class Test {
    public static void main(String[] args) {
        Person p1 = new Person();
        p1.setName("Sabbir");
        System.out.println(p1.getName());

    }
}
Comment

Java Encapsulation

public class Person {
  private String name; // private = restricted access

  // Getter
  public String getName() {
    return name;
  }

  // Setter
  public void setName(String newName) {
    this.name = newName;
  }
}
Comment

encapsulation java

Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the data it manipulates. Another way to think about encapsulation is, it is a protective shield that prevents the data from being accessed by the code outside this shield. 
Comment

what is encapsulation in java

1-ENCAPSULATION: We can hide direct access to data by using
private key and we can access private data by using getter and
setter method.
Comment

PREVIOUS NEXT
Code Example
Java :: display hello world in android app 
Java :: encryption 
Java :: java append to array 
Java :: java comment 
Java :: spring swagger ui login oauth2 
Java :: how to remove leading space in java 
Java :: Java Create a PrintWriter 
Java :: spring login response data 
Java :: contain java 
Java :: advantages of using java 
Java :: Java Abstract Class and Method 
Java :: package javafx.fxml does not exist 
Java :: syntax for java interfaces 
Java :: playwright java 
Java :: java code to get all leaf nodes of a xml 
Java :: output of this 
Java :: program Pr115_3; var k, n : integer; suma : real; begin readln(n); suma := 0; for k := 1 to n do suma := suma + 1 / sqr(2*k+1); writeln(suma); readln; end. 
Java :: intelij show method information 
Java :: condensed for loop java 
Java :: how to extract word from string in java 
Java :: influx cli with docker container 
Java :: sealed class java codegrepper 
Java :: java split not working on comma 
Java :: PlatformException (PlatformException(unknown, java.lang.Exception: Client is offline, {code: unknown, message: java.lang.Exception: Client is offline}, null)) 
Java :: i have use tried catch but still prints exception java 
Java :: set integer array value to null java 
Java :: @exceptionhandler spring boot annotation not found 
Java :: Zooming an Image using OpenCV in Java 
Java :: java code to implement hybrid interface 
Java :: number of zeros in a binary array 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =