Lec : 21 | java

          

LEC:21

Encapsulation in JAVA | use of get and set methods in JAVA








Source Code:
package oops;
import java.util.Scanner;
class Student {
//    data members
    private 
    int a,b;
//    member function 
    public
    void set(int a1,int b1)
    {
        a=a1;b=b1;
    }
    void get()
    {
        System.out.println("The value of a : "+a+" and b : "+ b);
    }
}

public class OOPS {
    public static void main(String[] args) {
        Student O1=new Student();
        O1.set(4, 7);
        O1.get();
    }

}

Comments

Popular posts from this blog

RunwayWithCode

web development Lectures

C++ Lectures