Java private 关键字
-
定义和用法
private关键字是用于属性,方法和构造函数的访问修饰符,使他们只在类内部访问。 -
示例
具有private属性的类:
尝试一下public class Person { private String fname = "John"; private String lname = "Doe"; private String email = "alex@cainiaoya.com"; private int age = 24; public static void main(String[] args) { Person myObj = new Person(); System.out.println("Name: " + myObj.fname + " " + myObj.lname); System.out.println("Email: " + myObj.email); System.out.println("Age: " + myObj.age); } }
-
相关页面
Java 教程:Java 修饰符