<> 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,
( Super detail )Eclipse Using tutorials —— use Eclipse Create first HelloWorld! Database operation 5 code implementation mysql Addition, deletion, modification and query of database What can MCU do , Do you have any interesting works made by MCU or open source hardware Go to the interview after reading this , Steady over ~~ Single linked list of primary data structure (C Language implementation )SQL Comprehensive questions Employee unit comprehensive questions Python Implementation of Hanoi Tower code VHDL——JK trigger It's over , Starting salary 30k