当前位置:网站首页>在本类私有属性直接使用?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()对其操作
边栏推荐
- Build the first neural network with pytoch and optimize it
- containerd1.5.5的安装
- 用Pytorch搭建第一個神經網絡且進行優化
- Learn how Alibaba manages the data indicator system
- Construire le premier réseau neuronal avec pytorch et optimiser
- 买卖股票费用计算
- Goldbach`s Conjecture
- Matlab tips (20) matrix analysis -- principal component regression
- Comment supprimer le crosstalk SiC MOSFET?
- Is it safe to open an account for mobile phone stock speculation?
猜你喜欢

Mysql8.0 forgot the root password

Learn how Alibaba manages the data indicator system

Construire le premier réseau neuronal avec pytorch et optimiser

Resource scheduling and task scheduling of spark

Explain observer mode

Application of energy management system in iron and steel enterprises

数据挖掘建模实战

Apache Doris becomes the top project of Apache

Calcul des frais d'achat et de vente d'actions

JMeter -- interface test 1
随机推荐
Matlab tips (20) matrix analysis -- principal component regression
学习阿里如何进行数据指标体系的治理
Implementation of code scanning login
[reprint] STM32 GPIO type
与普通探头相比,差分探头有哪些优点
Webrtc advantages and module splitting
Basic content learning of software testing (I)
JMeter -- interface test 1
Basic knowledge of hard disk (head, track, sector, cylinder)
Fire fighting work and measures in Higher Vocational Colleges
Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.
理解IO模型
如何抑制SiC MOSFET Crosstalk(串擾)?
The Falling Leaves
状态机程序框架
"Jianzhi offer" -- Interview Question 4: finding two-dimensional arrays
Avframe Memory Management API
Application of energy management system in iron and steel enterprises
Applet: traverse the value of an array in the list, which is equivalent to for= "list" list An item in comment
买卖股票费用计算