• Tidak ada hasil yang ditemukan

week12_lecture 1

N/A
N/A
Protected

Academic year: 2025

Membagikan "week12_lecture 1"

Copied!
7
0
0

Teks penuh

(1)

CPCS 202

(2)
(3)

The super Keyword

• Every object has a reference to itself called the this reference, and there are situations where a class needs to explicitly use the this reference when referring to its fields or

reference when referring to its fields or methods.

• Similarly, a class can use the super keyword to explicitly refer to a field or method that is inherited from a parent. You can think of

super as a child object’s reference to its

parent object.

(4)

public class Salary extends Employee {

public float salary; //Annual salary public float computePay()

{

System.out.println(“Computing salary pay for “ + super.name);

return salary/52;

} }

public void mailCheck() {

System.out.println(“Inside Salary mailCheck”);

super.mailCheck();

System.out.println(“Mailed check to “ + this.name + “ with salary “ + this.salary);

} }

(5)

The final Keyword

• The final keyword is used for creating constant variables.

• A final variable cannot be changed after it has

• A final variable cannot be changed after it has been assigned a value.

• Other two uses of the final keyword:

Final class. A class can be declared final. A final class cannot be subclassed.

Final method. A method can be declared final. A final method cannot be overridden.

(6)

Summary …

• Inheritance allows new class to extend an

existing class. The new class will inherit all the attributes and behaviour of the parent class.

attributes and behaviour of the parent class.

• The extends keyword is used to implement

inheritance. A class in Java can extend only one class.

• The parent object of a Java class is the

java.lang.Object, provided that it does not extends another class.

(7)

Summary

• Method overriding is when a child class contains the same method as its parent class.

• The super keyword is used by the child class to

• The super keyword is used by the child class to explicitly access the fields or methods of the

parent class.

• A final class cannot be extended. A final method cannot be overridden.

Referensi

Dokumen terkait

Second, the contribution of Islamic law to this discretion problem lies in the basic values that can be used as a reference to the practical level by referring to the ushul principles

This article will limit itself to the following aspects as they relate to the South African local government system, with reference to the City of Tshwane Metropolitan Municipality

• Creating an object requires you to first define an object class containing variables and/or function definitions and then using the “new” keyword to create an instance of the object

Internal Sovereignty means some persons, assembly of group of persons in every independent state have the final legal authority to command and enforce obedience.. This sovereignty

that every individual and every organ of society, keeping this Declaration constantly in mind, shall strive by teaching and education to promote respect for these rights and freedoms

Simply Linked List Classes Two classes are used: Node and List Declare Node class for the nodes element: object next: a link object reference to the next node in the list

Analytical Legal Positivism Analytical jurisprudence is the general name for the approach to Jurisprudence which concern itself mainly with classification of legal principles and