当前位置:网站首页>在本类私有属性直接使用?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()对其操作
边栏推荐
- 批量修改表和表中字段排序规则
- Construire le premier réseau neuronal avec pytorch et optimiser
- Webrtc advantages and module splitting
- Fire fighting work and measures in Higher Vocational Colleges
- Build the first neural network with pytoch and optimize it
- Quickly understand JVM structure and working principle
- 如何抑制SiC MOSFET Crosstalk(串擾)?
- Understanding the IO model
- Characteristics and prevention of electrical fire
- Common tools for interface testing --postman
猜你喜欢

【大案例】学成在线网站

containerd1.5.5的安装

Basic knowledge of hard disk (head, track, sector, cylinder)

Construire le premier réseau neuronal avec pytorch et optimiser

Learn how Alibaba manages the data indicator system

Data mining modeling practice

Webrtc advantages and module splitting

图解MySQL的binlog、redo log和undo log

Boundary value analysis method for learning basic content of software testing (2)

罗氏线圈工作原理
随机推荐
Implementation of single sign on
Calcul des frais d'achat et de vente d'actions
如何实现基于 RADIUS 协议的双因子认证 MFA?
学习阿里如何进行数据指标体系的治理
与普通探头相比,差分探头有哪些优点
spark的资源调度和任务调度
[.Net6] GRP server and client development cases, as well as the access efficiency duel between the minimum API service, GRP service and traditional webapi service
Goldbach`s Conjecture
Anniversary party
【无标题】
Boundary value analysis method for learning basic content of software testing (2)
Scenario method and error recommendation method for learning basic content of software testing (2)
Guangzhou: new financial activities and new opportunities for enterprises
How do I open an account on my mobile phone? Is it safe to open an account online now?
Basic content learning of software testing (I)
个人究竟如何开户炒股?在线开户安全么?
Which is a better ERP management system for electronic component sales?
Container adapter - stack: stack queue: queue priority_ Queue: priority queue
Implementation of single sign on
The Cassandra cluster reinstalls and starts from the node. An error is reported. There is an existing solution