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

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 :: the java_home environment variable is not defined correctly on mac 
Java :: array of string java 
Java :: basics of java 
Java :: import in java 
Java :: java byte data type 
Java :: insert node at end of doubly linked list 
Java :: join arrays in java 
Java :: POST method) in spring rest api 
Java :: top java interview coding questions 
Java :: object in java 
Java :: java literals 
Java :: java thread 
Java :: java string class 
Java :: how to use a while statement with char in java 
Java :: java stream Return sums of elements grouped by a remainder of division by the give divisor 
Java :: java 8 iterating and manipulating list 
Java :: reading 2d array in java 
Java :: foreach() java 
Java :: varstatus foreach jsp 
Java :: android adb is using too much cpu 
Java :: param vishisht seva medal 
Java :: prime numbers most efficient algorithm java 
Java :: java resultset to object 
Java :: transform primitive float array to float array 
Java :: force_dark_auto android webview 
Java :: .throwFor in java 
Java :: Java Standard Library Method 
Java :: setting a hint on a text field in javafx 
Java :: find the letter that occurs most in a string java 
Java :: Period java springboot 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =