- Java 9 with JShell
- Gastón C. Hillar
- 216字
- 2021-07-09 18:46:50
Test your knowledge
- When Java executes the code within a constructor:
- We cannot access any members defined in the class.
- There is already a live instance of the class. We can access methods defined in the class but we cannot access its fields.
- There is already a live instance of the class and we can access its members.
- Constructors are extremely useful to:
- Execute setup code and properly initialize a new instance.
- Execute cleanup code before the instance is destroyed.
- Declare methods that will be accessible to all the instances of the class.
- Java 9 uses one of the following mechanisms to automatically deallocate the memory used by instances that aren't referenced anymore:
- Instance map reduce.
- Garbage compression.
- Garbage collection.
- Java 9 allows us to define:
- A main constructor and two optional secondary constructors.
- Many constructors with different arguments.
- Only one constructor per class.
- Any new class we create that doesn't specify a superclass will be a subclass of:
java.lang.Base
java.lang.Object
java.object.BaseClass
- Which of the following lines create an instance of the
Rectangle
class and assign its reference to therectangle
variable:var rectangle = new Rectangle(50, 20);
auto rectangle = new Rectangle(50, 20);
Rectangle rectangle = new Rectangle(50, 20);
- Which of the following lines access the
width
field for therectangle
instance:rectangle.field
rectangle..field
rectangle->field
推薦閱讀
- Java程序設計與開發
- Spring技術內幕:深入解析Spring架構與設計
- Building Cross-Platform Desktop Applications with Electron
- 計算機應用基礎實踐教程
- Instant Nancy Web Development
- Swift 4 Protocol-Oriented Programming(Third Edition)
- Kotlin開發教程(全2冊)
- Java程序設計教程
- Three.js權威指南:在網頁上創建3D圖形和動畫的方法與實踐(原書第4版)
- 軟件測試技術
- JavaScript Unit Testing
- 前端架構設計
- C語言王者歸來
- Learning Redux
- AI輔助編程Python實戰:基于GitHub Copilot和ChatGPT