Download presentation
Presentation is loading. Please wait.
1
Final and Static Keywords
2
Creating constants There will be occasions where data items in a program have values that do not change. Maximum score in an exam (100) The number of hours in a day (24) The mathematical value of pie (3.14176) Do the values of these variables vary?
3
Constants Values that remain constant throughout a program (as opposed to variable) should be named and declared as constants Constants are declared like variables in Java except that they are preceded by the keyword final final int HOURS =24
4
Changing the Value Any attempt to change this value later in the program will result in a compile error. For example: final int HOURS =24 //create constant HOURS = 12 //will not compile!
5
The static keyword You might already have noticed the keyword static in front of the names of methods or attributes in some Java classes Static means that when any object in the class changes the value of the variable, that value changes for all objects in the class An attribute declared as static, will, if changed, change for all objects in the class
6
The static keyword Class BankAccount2 Private static double interestRate; Private void setInterestRate (double rateIn) { interestRate = rateIn: } double getInterestRate() { return InterestRate; }Phil.setInterestRate(5.2)Phil.getInterestRate()
7
Exam Topics
8
Topics Java Basics Primitive Data Types and Variables Expressions and Operators –Relational Operators –Arithmetic Operators Program Control –If statements –If else statements –Multiple Else if statements –Nested If Statements –Switch statements
9
Topics Program Control –For loops –While loops –Do while loops Classes and Objects Methods Getter and Setter Methods Constructors Access Protection and Visibility Modifiers Polymorphism –Overloading –Overriding
10
Topics Inheritance Final and Static
11
In Class Exam Students have 45 minutes to complete the exam 40 MCQ Questions Students will be awarded: –3 Marks for every correct answer –1 Mark will be deducted for each incorrect answer
12
Inclass Exam Please ensure to indicate your selected in both the boxes on this answersheet AND the EDPACK sheet In cases of discrepancies the answer indicated on the EDPACK sheet will be taken as the given answer Please ensure to use a pencil when populating the EDPACK sheet BRING A PENCIL Both this answerbook and the EDPACK sheet must be submitted.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.