Skip to content

Commit

Permalink
added
Browse files Browse the repository at this point in the history
  • Loading branch information
devrath committed Jan 26, 2024
1 parent bf58885 commit eb6e111
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class MainActivity : ComponentActivity() {

NavHost(
navController = navController,
startDestination = ModuleDemo.FlattenFlowsDemo.rout
startDestination = ModuleDemo.DemoSelection.rout
) {
// Selection Screen
composable(ModuleDemo.DemoSelection.rout) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import com.istudio.app.ui.composables.AppButton
import com.istudio.app.ui.composables.AppText

@Composable
fun KotlinBasicsDemo(navController: NavHostController) {
Expand Down Expand Up @@ -103,6 +104,22 @@ fun KotlinBasicsDemo(navController: NavHostController) {
viewModel.membersPrivateDemo()
})

Spacer(modifier = Modifier.height(16.dp))

AppButton(text = "Init block significance", onClick = {
viewModel.initBlockSignificanceDemo()
})

Spacer(modifier = Modifier.height(16.dp))

AppText(text = "Constructors Demo")

Spacer(modifier = Modifier.height(5.dp))

AppButton(text = "Primary Constructor", onClick = {
viewModel.primaryConstructorDemo()
})

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,46 @@ class KotlinBasicsDemoVm @Inject constructor( ) : ViewModel() {
class Person(name: String)
class Student(val name: String)


/**
* Init block significance
*/
fun initBlockSignificanceDemo() {
println("Before City Class construction")
val demo = City("New York")
println("After City Class construction")
demo.demo()
}

class City(val name: String){
init {
println("City is created with Name:-> $name")
}

fun demo(){
println("City construction is in progress")
}
}


/**
* Primary constructor demo
*/
fun primaryConstructorDemo() {
val science = Science()
val history = History()
// val maths = Maths() // Cannot access '<init>': it is private in 'Maths'
}

// Class with default constructor(way 1)
class Science()
// Class with default constructor(way 2)
class History constructor()
// Class with private constructor
class Maths private constructor()
// Class with protected constructor constructor
class Computers protected constructor()



}

0 comments on commit eb6e111

Please sign in to comment.