一个代码可以封装多个resquest进行调用,只是在调用的过程中必须保证方法名称和调用的方式一致。
封装的概念来自对面向对象的编程模式 比如说一个方法,你把他放到一个类里面, 下次如果别的地方要用到的话,直接调用这个方法就行了,不用再重新编写。
封装就是将 a b c 用private私有化,让别人不能直接访问,提供public get,set方法,来取得值,设置值;如 n.getA()*x*x+n.getB()*x+n.getC()==2*x*x+1*x+3 这样提高了代码安全性package Test
public class num {
private int a
private int b
public int c
public int getA() {
return a
}
public void setA(int a) {
this.a = a
}
public int getB() {
return b
}
public void setB(int b) {
this.b = b
}
public int getC() {
return c
}
public void setC(int c) {
this.c = c
}
}
class test3{
public static void main(String[] args) {
num n=new num()
int x=-1
n.setA(2)
n.setB(1)
n.setC(3)
if(n.getA()*x*x+n.getB()*x+n.getC()==2*x*x+1*x+3){
system.out.print(true)
}
}