<> example : Define a student class and encapsulate it

<> Quick encapsulation after definition

Right click to select cource >> go to >> generate getters and setters…

The code is as follows :
package inherit ; public class Student { private String name ; private int age ;
private String college ; private String depart ; public Student (){} public
Student (String name , int age , String college , String depart) {
this.setName(name); this.setAge(age); this.setCollege(college);
this.setDepart(depart); } public void setName(String name){ this.name = name; }
public void setAge(int age) { this.age = age ; } public void setCollege(String
college){ this.college = college ; } public void setDepart(String depart){
this.depart = depart ; } public String getName(){ return this.name ; } public
int getAge(){ return this.age ; } public String getCollege(){ return
this.college ; } public String getDepart(){ return this.depart; } public String
getInfo(){ return " Student information is as follows :" + "\n" + " full name :" + this.getName() + "\n" + " Age :" +
this.getAge() + "\n" + " school :" + this.getCollege() + "\n" + " college :" +
this.getDepart(); } } class test1{ public static void main (String args[]){
Student stu1 = new Student(" Zhang San " , 22 , "shu" , "computer science and
techololege") ; System.out.println(stu1.getInfo()); } }

Technology
©2019-2020 Toolsou All rights reserved,
Java Swing JList: List box components Accurate mobile phone number capture , Big data of operators The difference between memory overflow and memory leak , Causes and Solutions Website mobile phone number capture method stay Vue Use in Web Worker3 species Python data structure ,13 Creation methods , This is the conclusion , Great ! What's the difference in server prices ? Basic definition and use of function ‘ To be continued SQL Server Database Glossary Chrome OS, For programmers and Windows What does it mean ? Internet Marketing