日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

kotlin 类和对象_Kotlin程序| 类和对象的示例(带有学生数据)

發布時間:2025/3/11 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 kotlin 类和对象_Kotlin程序| 类和对象的示例(带有学生数据) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

kotlin 類和對象

In the below program, we are creating a student class to input and print the student data like name, age. It is a simple example of creating class in Kotlin.

在下面的程序中,我們將創建一個學生班級,以輸入和打印學生數據,例如姓名,年齡。 這是在Kotlin中創建類的簡單示例。

Note:

注意:

  • The compiler creates a default constructor if we do not declare a constructor.

    如果我們不聲明構造函數,則編譯器將創建默認構造函數。

  • Class properties must be initialized.

    類屬性必須初始化。

Kotlin學生課程 (Program for student class in Kotlin)

package com.includehelp// Class declaration, class Student{//member variables of classprivate var name: String=""private var age: Int=0//Member functions of class to set student namefun setStudentName(name:String){this.name=name}//Member functions of class to set student agefun setStudentAge(age:Int){this.age=age}//Member functions of class to return student detailsfun getStudentDetails():String{return "Name : $name, Age : $age"} }//Main function, Entry Point of Program fun main(args:Array<String>){//Create Object of Student Classval student1 = Student() // There is no 'new' keyword// set Student age and name to call member functions of classstudent1.setStudentName("Mike")student1.setStudentAge(30)//print Student details bt ccall getStudentDetails members functionsprintln("Student : ${student1.getStudentDetails()}")//Create Second object of student classval student2 = Student()student2.setStudentName("Irina")student2.setStudentAge(23)println("Student : ${student2.getStudentDetails()}") }

Output:

輸出:

Student : Name : Mike, Age : 30 Student : Name : Irina, Age : 23

翻譯自: https://www.includehelp.com/kotlin/example-of-class-and-object-with-student-data.aspx

kotlin 類和對象

總結

以上是生活随笔為你收集整理的kotlin 类和对象_Kotlin程序| 类和对象的示例(带有学生数据)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。