当前位置:网站首页>在本类私有属性直接使用?new()在使用!!!
在本类私有属性直接使用?new()在使用!!!
2022-06-28 09:06:00 【C_x_330】
已知有下列Test类的说明,在该类的main方法的横线处,则下列哪个语句是正确的?()
public class Test
{
private float f = 1.0f;
int m = 12;
static int n = 1;
public static void main (String args[])
{
Test t = new Test();
————————
}
}
t.f = 1; 正确this.n = 1;Test.m = 1;Test.f = 1;如果在同一个类中,就像这题构造一个实例对象去直接访问私有成员变量或私有方法是可以的,这个前提是你必须new()一个对象才能去调用这些私有属性,绝不能单独使用,否则还是报错!
但是,即便在同一个包下不同的类,例如:B类有私有属性,你在A再创建一个B类的实例对象,这个时候你就不能直接调用私有属性了,你必须通过get()、set()对其操作
边栏推荐
- Goldbach`s Conjecture
- How to solve the problem of high concurrency and seckill
- 实现全局双指长按返回桌面
- Fire fighting work and measures in Higher Vocational Colleges
- Webrtc advantages and module splitting
- How do individuals open accounts to speculate in stocks? Is online account opening safe?
- Is it safe to open an account for online stock speculation?
- Music website design based on harmonyos (portal page)
- Apache Doris 成为 Apache 顶级项目
- [big case] Xuecheng online website
猜你喜欢
用Pytorch搭建第一個神經網絡且進行優化
理解IO模型
Installation of containerd1.5.5
从知识到智慧:知识图谱还要走多远?
DEJA_ Vu3d - 051 of cesium function set - perfect realization of terrain excavation
Discussion on safety management of centralized maintenance construction site of substation under the mode of operation and maintenance
Webrtc advantages and module splitting
Matlab tips (20) matrix analysis -- principal component regression
Expérience d'optimisation SQL: de 30248 secondes à 0001 secondes
[untitled]
随机推荐
Discussion on the practice of fire emergency lighting system in the field of building electrical design
[reprint] STM32 GPIO type
Decision table method for basic content learning of software testing (2)
DEJA_VU3D - Cesium功能集 之 051-地形开挖完美实现
Key points of building fire protection design
A - deep sea exploration
FatMouse and Cheese
【无标题】
如何实现基于 RADIUS 协议的双因子认证 MFA?
中金财富开户安全吗?怎么收费?
spark的资源调度和任务调度
Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.
Ffmpeg streaming fails to update header with correct duration
【云原生 | Kubernetes篇】深入了解Pod(六)
Copy & Deepcopy
Application of current limiting protector in preventing electrical fire in shopping malls
状态机程序框架
Calculation of stock purchase and sale expenses
Using transform:scale causes the page mouse hover event to disappear
个人究竟如何开户炒股?在线开户安全么?