在 Java 中进行向上转换时,每个术语的含义是什么?
因此,说我有一辆汽车和子类汽车,
Vehicle v = new Vehicle();
Car c = new Car();
当我们这样做时,它在主(Java)中实例化对象...
Vehicle c1 = new Car();
车辆一词代表什么?在此铸件中,汽车一词代表什么?
(基本上是在采访中被问到什么“类型” C1是什么,我无法弄清楚C1是否是类型的车辆,使用汽车实施或类型的汽车,只能使用车辆的方法)
So say I have a class Vehicle and subclass car that have instantiated objects in the main (Java)
Vehicle v = new Vehicle();
Car c = new Car();
When we do...
Vehicle c1 = new Car();
What does the word vehicle represent and what does the word car represent in this casting?
(I was basically asked in an interview what "type" c1 is and I couldn't figure out if c1 is type vehicle with a car implementation or type Car that can only use Vehicle's methods)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
C1是一个可以保存任何车辆的变量。
它指的物体是汽车,它是车辆;
考虑一下:
变量C1不会神奇地改变其类型。它以顺序指的两个对象具有(无效)不同的类型。
我的思维方式重要的是要了解对象和变量之间的差异。
c1 is a variable that can hold a reference to any Vehicle.
The object it refers to is a Car, which is a Vehicle;
Consider this:
The variable c1 does not magically change its type. The two objects it refers to in sequence have (unmagically) different types.
The important thing in this to my way of thinking is to understand the difference between object and variable.
什么是对象?
对象是现实世界或软件条目,具有属性(实例字段)和行为(实例方法)。该对象是使用堆中的 new 运算符创建的。例如 new ClassName(); 。当类加载到内存中时,对象就会被实例化。对象也称为实例。
什么是参考?
引用保存对象或实例的地址。每当我们想要调用实例方法时,我们都会使用此引用来保存对象的地址。引用就像 C++ 指针。
更多信息请点击这里 https://levelup .gitconnected.com/what-is-difference- Between-reference-object-instance-and-class-24721e526f9b
What is an Object?
An object is a real-world or software entry which has attributes(instance fields) and behavior(instance methods). The object is created with a new operator in the heap. e.g. new ClassName(); . Objects are instantiated when class is loaded into memory. Objects are also called as Instances.
What is a Reference?
Reference holds the address of an object or instance. Whenever we want to call instance methods, we use this reference which holds the address of the object. References are like C++ pointers.
More information here https://levelup.gitconnected.com/what-is-difference-between-reference-object-instance-and-class-24721e526f9b