JAVA - How To Create A Class In Java NetBeans

JAVA - How To Create A Class In Java Using NetBeans

__________________________________________________________________________

In This Java Code We Will See How To Make A Class In Java NetBeans Programming Language.

Project Source Code:

package javadb_001;

public class User{
    private int id;
    private String fname;
    private String lname;
    private int age;

    public User(){}

    public User(int _id,String _fname,String _lname,int _age){
        this.id = _id;
        this.fname = _fname;
        this.lname = _lname;
        this.age = _age;           
    }
    
    public int getId(){
     return this.id;
    }
    public void setId(int id){
        this.id = id;
    }
    
    public String getFname(){
        return this.fname;
    }
    
    public void setFname(String fname){
     this.fname = fname;    
    }
    
    public String getLname(){
        return this.lname;
    }
    
    public void setLname(String lname){
        this.lname = lname;
    }
    
    public int getAge(){
        return this.age;
    }
    
    public void setAge(int age){
        this.age = age;
    }


public static void main(String[] args){
        
        User u = new User(999,"AAAA","BBBB",100);
        int id = u.getId();
        String fname = u.getFname();
        String lname = u.getLname();
        int age = u.getAge();
        System.out.println("ID: "+id);
        System.out.println("FNAME: "+fname);
        System.out.println("LNAME: "+lname);
        System.out.println("AGE: "+age);
}

}

//////////////////  OUTPUT: ID: 999
                                        FNAME: AAAA
                                        LNAME: BBBB
                                        AGE: 100




Share this

Related Posts

Previous
Next Post »