当前位置:网站首页>Use of constructors
Use of constructors
2022-06-11 06:00:00 【visionkiwi】
package oop.Demo01;
// There is only one specification for a project main Method
public class Application {
public static void main(String[] args) {
//new key word An object is instantiated
Person person = new Person(" skin ",12);
System.out.println(person.name+person.age);
}
}
package oop.Demo01;
public class Person {
// Even if a class doesn't write anything , It also has a way
// The definition constructor of the display
String name;
int age;
/* Default constructor */
// No arguments structure
// Instantiate the initial value
//1. Use new keyword , The essence is to call the constructor again
//2. Used to initialize values
public Person(){
this.name = " Pixiaopi ";// Define the initial value ( There can be no )
}
/* heavy load */
// There are parametric structures : Once a parametric construct is defined , A parameterless construct must display the definition
public Person(String test,int age){
this.name = test;
this.age = age;
}
}
/* Constructors : 1. Same as class name 2. no return value effect : 1.new, The essence is calling constructor 2. Initialize the value of the object Be careful : 1. After defining a parametric construct , If you want to use a nonparametric construct , The definition of the display is a parameterless construct idea Shortcut key :Alt + Insert ( Quick build construction ) this. = The current class */
边栏推荐
- How to deal with message blackout and message sending failure of Aurora im
- ELK日志系统实战(五):安装vector并将数据输出到es、clickhouse案例
- Aurora im live chat
- JIRA software annual summary: release of 12 important functions
- After adding the header layout to the recyclerview, use the adapter Notifyitemchanged (POS,'test') invalid local refresh
- 配置Rust编译环境
- NDK learning notes (IX) POSIX sockect connection oriented communication
- Further efficient identification of memory leakage based on memory optimization tool leakcanary and bytecode instrumentation technology
- 那个酷爱写代码的少年后来怎么样了——走近华为云“瑶光少年”
- Sword finger offer 04: find in 2D array
猜你喜欢

Implementation of data access platform scheme (Youzu network)

Do you know the functions of getbit and setbit in redis?
![[IOS development interview] operating system learning notes](/img/1d/2ec6857c833de00923d791f3a34f53.jpg)
[IOS development interview] operating system learning notes

Getting started with kotlin

Wechat custom component - style - slot

Super details to teach you how to use Jenkins to realize automatic jar package deployment

Getbackgroundaudiomanager controls music playback (dynamic binding of class name)

Do we really need conference headphones?

Can Amazon, express, lazada and shrimp skin platforms use the 911+vm environment to carry out production number, maintenance number, supplement order and other operations?

ThymeleafEngine模板引擎
随机推荐
Elk log system practice (VI): comparison between vector and filebeat for technology selection
Global case | how Capgemini connects global product teams through JIRA software and confluence
[daily exercises] merge two ordered arrays
Getbackgroundaudiomanager controls music playback (dynamic binding of class name)
[元数据]LinkedIn-DataHub
What happened to the young man who loved to write code -- approaching the "Yao Guang young man" of Huawei cloud
JS -- reference type
ImageView supporting single finger sliding and double finger scaling
Fix [no Internet, security] problem
Install Oracle Database
[daily exercise] 217 Duplicate element exists
NDK learning notes (VIII) thread related
使用Batch管理VHD
Free get | full function version of version control software
Multithreading tutorial (XXVI) field updater and atomic accumulator
Super (subclass)__ init__ And parent class__ init__ ()
Vscode plug-in development
Sign for this "plug-in" before returning home for the new year
Qmake implementation of QT project Pro script to vs solution
Deployment of Flink