Mobile Computing Lab2
Mobile Computing Lab2
u OOP in Dart
u Constructor in Dart
u Encapsulation in Dart
u Inheritance in Dart
u Polymorphism in Dart
u
u Output : Area of rectangle is 50.
Constructor in Dart
u The constructor’s name should be the same as the class name.
u Constructor doesn’t have any return type.
u When you create a object of a class, the constructor is called automatically.
u It is used to initialize the values when an object is created.
u Output : Constructor called Name: John Age: 20 Roll Number: 1
u Output : Name: John
Phone1: 1234567890
Phone2: null
Subject: Maths
Constructor With Optional Parameters
u Output : Name: John
Age: 30
Subject: N/A
Salary: 0
Encapsulation In Dart
u hiding data within a library, preventing it from outside factors. It helps you control
your program and prevent it from becoming too complicated.
u Declaring the class properties as private by using underscore(_).
u Output : Jack
u final keyword Read-only Properties
u Properties declared with the final keyword must be initialized at the time
of declaration. You can also initialize them in the constructor .
u Output : ABC School
u Why Encapsulation Is Important?
• Data Hiding: Encapsulation hides the data from the outside world. It
prevents the data from being accessed by the code outside the class.
This is known as data hiding.
u Dart supports single inheritance, which means that a class can only
inherit from a single class. Dart does not support multiple inheritance