Answer: The primary constructor is part of the class header. Unlike Java, you don't need to declare a constructor in the body of the class. Here's an example:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To enable ProGuard in your project, edit project.properties | |
# to define the proguard.config property as described in that file. | |
# | |
# Add project specific ProGuard rules here. | |
# By default, the flags in this file are appended to flags specified | |
# in ${sdk.dir}/tools/proguard/proguard-android.txt | |
# You can edit the include path and order by changing the ProGuard | |
# include property in project.properties. | |
# | |
# For more details, see |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Log; | |
import com.appandweb.prjtestdrivendev.BuildConfig; | |
import com.squareup.okhttp.Interceptor; | |
import com.squareup.okhttp.Request; | |
import com.squareup.okhttp.Response; | |
import com.squareup.okhttp.ResponseBody; | |
import java.io.IOException; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
// Pair Example with infix notation | |
var pairExample = 1 to 3 | |
println("${pairExample.second}") | |
// pair with object notation | |
var pairExampleObj = Pair(3, 4) | |
println("the value be ${pairExampleObj.first}") | |
} | |
###Output### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
//To accept any datatype we have to use Any datatype | |
var anyDatatype: Any = 1 //it is accepting Int | |
println("the value is ${anyDatatype} ") | |
anyDatatype="Hello" // it is accepting String | |
println("the value is ${anyDatatype} ") | |
} | |
###Output### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
// here there is not Datatype deceleration | |
var check = "Hello" | |
var number = 1 | |
println("the value of check ${check} \n ${number}") | |
// if infered type is done then we can not change it's datatype | |
// number="String" //Error | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
val hello = "hello" | |
//value can not be reinitialized because it is like final variable in java | |
hello = "dlkjf" // it will produce an compile time error | |
println("$hello") | |
} | |
###output### | |
hello |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
//var variable is decleared | |
var name = "name Check" | |
println(name) | |
//changed the value of the variable | |
name="hell" | |
println("name is $name" + " check ") | |
} | |
###output### | |
name Check |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DemoConstructorOverload | |
{ | |
/** | |
*Constructor means method name is same as classname and no return type | |
*DemoConstructorOverload() is constructo | |
*/ | |
DemoConstructoroverload() | |
{ | |
System.out.println("hello default constructor"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:id="@+id/activity_animation_on_click_test" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:paddingBottom="@dimen/activity_vertical_margin" | |
android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin" | |
tools:context="com.compindia.viewstateanimationapp.AnimationOnClickTestActivity"> |