Final and Static Keywords. Creating constants  There will be occasions where data items in a program have values that do not change.  Maximum score.

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
Access to Names Namespaces, Scopes, Access privileges.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
19-Jun-15 Access to Names Namespaces, Scopes, Access privileges.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
28-Jun-15 Access to Names Namespaces, Scopes, Access privileges.
CS102--Object Oriented Programming Review 1: Chapter 1 – Chapter 7 Copyright © 2008 Xiaoyan Li.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
Chapter 7: User-Defined Methods
Chapter 10: Inheritance and Polymorphism
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Inheritance and Subclasses in Java CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University.
Java Course Outline Kumar Harshit, USW. Course Description Teaches students to program using the Java programming language with the help of the Netbeans.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Java Programming, Second Edition Chapter Four Advanced Object Concepts.
Java Tutorial. Object-Oriented Programming Concepts Object –a representation of some item state  fields/members and should be encapsulated behavior 
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Inheritance Extending Class Functionality. Polymorphism Review Earlier in the course, we examined the topic of polymorphism. Many times in coding, we.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
ILM Proprietary and Confidential -
Chapter 4 -2 part Writing Classes 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All.
Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this.
1 final (the keyword, not the exam). 2 Motivation Suppose we’ve defined an Employee class, and we don’t want someone to come along and muck it up  E.g.,
Chapter Outline What inheritance is Calling the superclass constructor Overriding superclass methods Protected members Chains of inheritance The Object.
Topic 4 Inheritance.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
Java Class Structure. Class Structure package declaration import statements class declaration class (static) variable declarations* instance variable.
1 Chapter 5: Defining Classes. 2 Basics of Classes An object is a member of a class type What is a class? Fields & Methods Types of variables: –Instance:
Class and Structure. 2 Structure Declare using the keyword struct purpose is to group data Default visibility mode is public A struct doesn't have a constructor.
Arithmetic, Class Variables and Class Methods Week 11
By Mr. Muhammad Pervez Akhtar
Inheritance and Subclasses CS 21a. 6/28/2004 Copyright 2004, by the authors of these slides, and Ateneo de Manila University. All rights reserved L16:
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
A High Flying Overview CS139 – Fall 2010 How far we have come.
9.1 CLASS (STATIC) VARIABLES AND METHODS Defining classes is only one aspect of object-oriented programming. The real power of object-oriented programming.
CPSC 233 Tutorial 12 March 4/5 th, TopHat Quiz int[] a = {0}; int[] b = {1}; a = b; What is the value of a[0] i) 0 ii) 1.
Chapter 7 User-Defined Methods.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Inheritance and Polymorphism
Chapter 11: Inheritance and Polymorphism
Creating Your OwnClasses
Namespaces, Scopes, Access privileges
Mumbai University - B.Sc.IT: Semester - VI - C# (Question Paper) [IDOL - Old Course] [May ]
CSC 205 Java Programming II
CS139 – Fall 2010 How far we have come
Methods Additional Topics
Defining Your Own Classes Part 1
Conditional Statements
د.سناء الصايغ الفصل الأول البرمجة الشيئية
Group Status Project Status.
CHAPTER 6 GENERAL-PURPOSE METHODS
Namespaces, Scopes, Access privileges
Building Java Programs
CIS 199 Final Review.
Review of Previous Lesson
Object Oriented Programming
Assessment – Java Basics: Part 2
Final and Abstract Classes
Final Review Dr. Xiaolin Hu.
Corresponds with Chapter 5
Building Java Programs
Presentation transcript:

Final and Static Keywords

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 ( )  Do the values of these variables vary?

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

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!

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

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()

Exam Topics

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

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

Topics  Inheritance  Final and Static

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

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.