SlideShare a Scribd company logo
1 of 26
Android Application Development
Kotlin is a relatively new programming language
developed by JetBrains for modern multiplatform
applications. Nowadays, Kotlin is widely used for Android
development instead of Java. It is because Kotlin is safe,
concise, and fun to read and write.
Kotlin Overview
History of Kotlin
Apps Built in Kotlin
Types of apps that can be built using Kotlin
• Kotlin is a relatively new programming language developed by JetBrains for
modern multiplatform applications. Nowadays, Kotlin is widely used for Android
development instead of Java. It is because Kotlin is safe, concise, and fun to
read and write.
About Kotlin Programming
•Open Source - The Kotlin compiler, Intellij IDEA plugin, and build tools are all open source.
•Interoperable - Kotlin is 100 percent interoperable with Java. This means all your current
Java/Android code works seamlessly with Kotlin.
•Concise - Compared to Java, Kotlin code are much more concise. Also, Kotlin code is much
more expressive (easier to understand and write).
•Tool-friendly - Kotlin is developed by JetBrains, the company renowned for creating
development tools. You can choose any Java IDE to write Koltin code.
Why Learn Kotlin?
•Kotlin is 100 percent interoperable with Java. Hence your Java/Android code works with
Kotlin.
•Kotlin allows you to cut off the lines of code by approximately 40% (compared to Java).
•Learning Kotlin is easy. It is particularly easy if you already know Java.
•Kotlin is tool-friendly. You can use any Java IDE or command line to run Kotlin.
Overview of Basic Syntax
• Function
• Variable
• Class
• Constructors
• Comments
Comments
• Single Line Comment
//
• Multiline Comment
• /* ---------- */
Variable
/*
* This is main function. Entry point of the application.
* */
fun main(args: Array<String>) {
var myNumber = 10 // Int
var myDecimal = 1.0 // Float
var isActive = true // Boolean
var myString: String // Mutable String
myString = "Hello World"
myString = "Another World"
val myAnotherString = "My constant string value" // Immutable String
// myAnotherString = "some value" // NOT ALLOWED, since it is immutable
print(myNumber)
• }
Function
fun main(args: Array<String>) {
var name: String
name=“ABC”
print (name)
display()
}
fun display() //Simple Function
{
print(“Hello all”)
}
fun main(args: Array<String>) {
var name: String
name=“ABC”
//print (name) // instead of printing name in main function lets print
through user define function
display(name)
}
fun display(name: String) //Parameterized Function
{
print(“Name is”+name)
}
fun main(args: Array<String>) {
var name: String
name=“ABC”
var p1= Person()
p1.display(name)
}
class Person { // Class
fun display(name: String) //Parameterized Function
{
print(“Name is”+name)
}
}
fun main(args: Array<String>) {
var p1= Person()
p1.name=“ABC”
p1.display(p1.name)
}
class Person { // Class
fun display(name: String) //Parameterized Function
{
var name: String= “ “
print(“Name is”+name)
}
}
fun main(args: Array<String>) {
var p1 = Person()
p1.name = “ABC”
print("The name of the person is ${p1.name}")
}
class Person {
var name: String = ""
}
/*
* Class, Primary Constructor, Secondary Constructor and Init Block
* */
fun main(args: Array<String>) {
var student = Student("Steve", 10)
println(student.id)
}
class Student(var name: String) {
var id: Int = -1
init {
println("Student has got a name as $name and id is $id")
}
constructor(n: String, id: Int): this(n) {
// The body of the secondary constructor is called after init block
this.id = id
}
}
fun main(args: Array<String>) {
var dog = Dog()
dog.bread = "labra"
dog.color = "black"
dog.bark()
dog.eat()
var cat = Cat()
cat.age = 7
cat.color = "brown"
cat.meow()
cat.eat()
var animal = Animal()
animal.color = "white"
animal.eat()
}
open class Animal {
var color: String = ""
fun eat() {
println("Eat")
}
}
class Dog : Animal() {
var bread: String = ""
fun bark() {
println("Bark")
}
}
class Cat : Animal() {
var age: Int = -1
fun meow() {
println("Meow")
}
}
fun main(args: Array<String>) {
var dog = MyDog()
println(dog.color)
dog.eat()
}
open class MyAnimal {
open var color: String = "White"
open fun eat() {
println("Animal Eating")
}
}
class MyDog : MyAnimal() {
var bread: String = ""
override var color: String = "Black"
fun bark() {
println("Bark")
}
override fun eat() {
super<MyAnimal>.eat()
println("Dog is eating")
}
}
fun main(args: Array<String>) {
var dog = TheDog("Black", "Pug")
}
open class TheAnimal{
var color: String = ""
constructor(color: String) {
this.color = color
println("From Animal: $color")
}
}
class TheDog : TheAnimal{
var bread: String = ""
constructor(color: String, breed:
String): super(color) {
this.bread = breed
println("From Dog: $color and
$breed")
}
}
Android Application Development (1).pptx

More Related Content

Similar to Android Application Development (1).pptx

Intro to Kotlin
Intro to KotlinIntro to Kotlin
Intro to KotlinMagda Miu
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with AndroidKurt Renzo Acosta
 
KotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptxKotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptxIan Robertson
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyMobileAcademy
 
MOOC_PRESENTATION_KOTLIN[1].pptx
MOOC_PRESENTATION_KOTLIN[1].pptxMOOC_PRESENTATION_KOTLIN[1].pptx
MOOC_PRESENTATION_KOTLIN[1].pptxkamalkantmaurya1
 
Kotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsKotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsJigar Gosar
 
Kotlin for Android Developers - 1
Kotlin for Android Developers - 1Kotlin for Android Developers - 1
Kotlin for Android Developers - 1Mohamed Nabil, MSc.
 
BangaloreJUG introduction to kotlin
BangaloreJUG   introduction to kotlinBangaloreJUG   introduction to kotlin
BangaloreJUG introduction to kotlinChandra Sekhar Nayak
 
Dear Kotliners - Java Developers are Humans too
Dear Kotliners - Java Developers are Humans tooDear Kotliners - Java Developers are Humans too
Dear Kotliners - Java Developers are Humans tooVivek Chanddru
 
Programming with Kotlin
Programming with KotlinProgramming with Kotlin
Programming with KotlinDavid Gassner
 
Kotlin fundamentals - By: Ipan Ardian
Kotlin fundamentals - By: Ipan ArdianKotlin fundamentals - By: Ipan Ardian
Kotlin fundamentals - By: Ipan ArdianRizal Khilman
 
Kotlin Fundamentals
Kotlin Fundamentals Kotlin Fundamentals
Kotlin Fundamentals Ipan Ardian
 
Getting Started With Kotlin Development - Rivu
Getting Started With Kotlin Development - Rivu Getting Started With Kotlin Development - Rivu
Getting Started With Kotlin Development - Rivu CodeOps Technologies LLP
 

Similar to Android Application Development (1).pptx (20)

Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
 
Fall in love with Kotlin
Fall in love with KotlinFall in love with Kotlin
Fall in love with Kotlin
 
Intro to Kotlin
Intro to KotlinIntro to Kotlin
Intro to Kotlin
 
Koin Quickstart
Koin QuickstartKoin Quickstart
Koin Quickstart
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with Android
 
KotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptxKotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptx
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRready
 
MOOC_PRESENTATION_KOTLIN[1].pptx
MOOC_PRESENTATION_KOTLIN[1].pptxMOOC_PRESENTATION_KOTLIN[1].pptx
MOOC_PRESENTATION_KOTLIN[1].pptx
 
moocs_ppt.pptx
moocs_ppt.pptxmoocs_ppt.pptx
moocs_ppt.pptx
 
Kotlin Basic & Android Programming
Kotlin Basic & Android ProgrammingKotlin Basic & Android Programming
Kotlin Basic & Android Programming
 
Kotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsKotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrains
 
Kotlin for Android Developers - 1
Kotlin for Android Developers - 1Kotlin for Android Developers - 1
Kotlin for Android Developers - 1
 
BangaloreJUG introduction to kotlin
BangaloreJUG   introduction to kotlinBangaloreJUG   introduction to kotlin
BangaloreJUG introduction to kotlin
 
Compose Camp Session 1.pdf
Compose Camp Session 1.pdfCompose Camp Session 1.pdf
Compose Camp Session 1.pdf
 
Kotlin intro
Kotlin introKotlin intro
Kotlin intro
 
Dear Kotliners - Java Developers are Humans too
Dear Kotliners - Java Developers are Humans tooDear Kotliners - Java Developers are Humans too
Dear Kotliners - Java Developers are Humans too
 
Programming with Kotlin
Programming with KotlinProgramming with Kotlin
Programming with Kotlin
 
Kotlin fundamentals - By: Ipan Ardian
Kotlin fundamentals - By: Ipan ArdianKotlin fundamentals - By: Ipan Ardian
Kotlin fundamentals - By: Ipan Ardian
 
Kotlin Fundamentals
Kotlin Fundamentals Kotlin Fundamentals
Kotlin Fundamentals
 
Getting Started With Kotlin Development - Rivu
Getting Started With Kotlin Development - Rivu Getting Started With Kotlin Development - Rivu
Getting Started With Kotlin Development - Rivu
 

Recently uploaded

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

Android Application Development (1).pptx

  • 2.
  • 3.
  • 4. Kotlin is a relatively new programming language developed by JetBrains for modern multiplatform applications. Nowadays, Kotlin is widely used for Android development instead of Java. It is because Kotlin is safe, concise, and fun to read and write.
  • 7. Apps Built in Kotlin
  • 8. Types of apps that can be built using Kotlin
  • 9. • Kotlin is a relatively new programming language developed by JetBrains for modern multiplatform applications. Nowadays, Kotlin is widely used for Android development instead of Java. It is because Kotlin is safe, concise, and fun to read and write.
  • 10. About Kotlin Programming •Open Source - The Kotlin compiler, Intellij IDEA plugin, and build tools are all open source. •Interoperable - Kotlin is 100 percent interoperable with Java. This means all your current Java/Android code works seamlessly with Kotlin. •Concise - Compared to Java, Kotlin code are much more concise. Also, Kotlin code is much more expressive (easier to understand and write). •Tool-friendly - Kotlin is developed by JetBrains, the company renowned for creating development tools. You can choose any Java IDE to write Koltin code. Why Learn Kotlin? •Kotlin is 100 percent interoperable with Java. Hence your Java/Android code works with Kotlin. •Kotlin allows you to cut off the lines of code by approximately 40% (compared to Java). •Learning Kotlin is easy. It is particularly easy if you already know Java. •Kotlin is tool-friendly. You can use any Java IDE or command line to run Kotlin.
  • 11. Overview of Basic Syntax • Function • Variable • Class • Constructors • Comments
  • 12. Comments • Single Line Comment // • Multiline Comment • /* ---------- */
  • 13. Variable /* * This is main function. Entry point of the application. * */ fun main(args: Array<String>) { var myNumber = 10 // Int var myDecimal = 1.0 // Float var isActive = true // Boolean var myString: String // Mutable String myString = "Hello World" myString = "Another World" val myAnotherString = "My constant string value" // Immutable String // myAnotherString = "some value" // NOT ALLOWED, since it is immutable print(myNumber) • }
  • 14. Function fun main(args: Array<String>) { var name: String name=“ABC” print (name) display() } fun display() //Simple Function { print(“Hello all”) }
  • 15. fun main(args: Array<String>) { var name: String name=“ABC” //print (name) // instead of printing name in main function lets print through user define function display(name) } fun display(name: String) //Parameterized Function { print(“Name is”+name) }
  • 16. fun main(args: Array<String>) { var name: String name=“ABC” var p1= Person() p1.display(name) } class Person { // Class fun display(name: String) //Parameterized Function { print(“Name is”+name) } }
  • 17. fun main(args: Array<String>) { var p1= Person() p1.name=“ABC” p1.display(p1.name) } class Person { // Class fun display(name: String) //Parameterized Function { var name: String= “ “ print(“Name is”+name) } }
  • 18. fun main(args: Array<String>) { var p1 = Person() p1.name = “ABC” print("The name of the person is ${p1.name}") } class Person { var name: String = "" }
  • 19.
  • 20.
  • 21.
  • 22. /* * Class, Primary Constructor, Secondary Constructor and Init Block * */ fun main(args: Array<String>) { var student = Student("Steve", 10) println(student.id) } class Student(var name: String) { var id: Int = -1 init { println("Student has got a name as $name and id is $id") } constructor(n: String, id: Int): this(n) { // The body of the secondary constructor is called after init block this.id = id } }
  • 23. fun main(args: Array<String>) { var dog = Dog() dog.bread = "labra" dog.color = "black" dog.bark() dog.eat() var cat = Cat() cat.age = 7 cat.color = "brown" cat.meow() cat.eat() var animal = Animal() animal.color = "white" animal.eat() } open class Animal { var color: String = "" fun eat() { println("Eat") } } class Dog : Animal() { var bread: String = "" fun bark() { println("Bark") } } class Cat : Animal() { var age: Int = -1 fun meow() { println("Meow") } }
  • 24. fun main(args: Array<String>) { var dog = MyDog() println(dog.color) dog.eat() } open class MyAnimal { open var color: String = "White" open fun eat() { println("Animal Eating") } } class MyDog : MyAnimal() { var bread: String = "" override var color: String = "Black" fun bark() { println("Bark") } override fun eat() { super<MyAnimal>.eat() println("Dog is eating") } }
  • 25. fun main(args: Array<String>) { var dog = TheDog("Black", "Pug") } open class TheAnimal{ var color: String = "" constructor(color: String) { this.color = color println("From Animal: $color") } } class TheDog : TheAnimal{ var bread: String = "" constructor(color: String, breed: String): super(color) { this.bread = breed println("From Dog: $color and $breed") } }