You are on page 1of 29

1.8.

Class constructors
Subject: Android fundamentals for Smart Home
Mgtr. José Alcides RumipambaLópez
Constructors types
1.9. Encapsulation and
visibility
Subject: Android fundamentals for Smart Home
Mgtr. José Alcides RumipambaLópez
Encapsulation

▪ The encapsulation is to hide


the methods and attributes
of an object.
Visibility

▪ These are restrictions that allow or deny


access to methods and attributes of a
class.
▪ Public: Accessible from any class.
▪ Private: Accessible only by the current
class.
▪ Protected: Accessible only by the current
class, daughters classes and classes of the
same package.
▪ Nothing: Accessible only by classes of the
same package.
Getter and setter methods

▪ These are used for consult and modify the private attributes of a
class.
Getter and setter methods

Private attributes:
Using getter and setter methods

Result:
Using getter and setter methods

Classwork # 4:
Develop the necessary code in the main class of “Mathematics V1” to
obtain the prime, pair and odd number and modify these using
keyboard.

Android for smart homes


9
Mgtr. José Alcides RumipambaLópez
1.10. Inheritance
Subject: Android fundamentals for Smart Home
Mgtr. José Alcides RumipambaLópez
Inheritance

Inheritance is to construct a child


class of a parent class.
▪ Allows reuse code.
▪ The child class inherits the
attributes and methods of the
parent class.
Inheritance example

▪ Create a new class into “Mathematics_V1” named “DecimalNumber”


and extend it from “Number”.
Inheritance example

Result:
Inheritance example

Classwork # 5:
Create a new class into “Mathematics_V1” named “NegativeNumber”
that inherits from “DecimalNumber” and add a new attribute designate
“NegativeNumber” .

Modify the main class for show the new result.

Android for smart homes


14
Mgtr. José Alcides RumipambaLópez
Mathematics_V1
Class and object concept

Classwork # 6:
Program the respective code for
show the system that shows the
figure.

Modify the main class to display


the new result of each class.

Android for smart homes


Mgtr. José Alcides RumipambaLópez
16
1.11. Polymorphism,
interface and list
Subject: Android fundamentals for Smart Home
Mgtr. José Alcides RumipambaLópez
Example of SeminaryStudents_V1 class

▪ Create a new project named


“SeminaryStudents_V1”.
▪ Make also two classes named
“MainClass” and “Stundet”.
Example of SeminaryStudents_V1 class

Student
- Name: String
- Address: String
- Picture: String
- Age: Integer
- Phone: Integer
- Commentary: String

+Student(name: String, address: String, age: int, phone: int, commentary:String)


+toStringStudents(): String
Example of SeminaryStudents_V1 class
Example of SeminaryStudents_V1 class

Test of generated code from main class.


Polymorphism

▪ Consist in to declare an object of a parent class but instantiate it with


the constructor of the child class.

Example:
<Parent class> OBJECT = new <Child class>(settings)
Interface

▪ The interface is an abstract class that contain methods but these not
implemented. It can also contain attributes but static and final type.

Example:
List

▪ The list is a vector that organize elements in sequential order, and


each element have an identifier of position beginning by zero.

Example:
List example
List example

To implement methods of interface:


List example

Test of generated code from main class.


Interface with ULM

Example:
List example

Classwork # 7:
▪ Build a system that
show the figure:

You might also like