lecture-24 - Information Hiding and Visibility Modifiers...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Object Oriented Programming Java - Defining Own Classes R.B. Lenin Winter - 2006 DA-IICT 23 Information Hiding and Visibility Modifiers • The visibility modifier public designates the setExchangeRate method as accessible from outside methods . – If two methods belong to different classes, then they are outside methods relative to each other
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object Oriented Programming Java - Defining Own Classes R.B. Lenin Winter - 2006 DA-IICT 24 Information Hiding and Visibility Modifiers • Class constants may be declared public because: – A constant is “read only” by nature – A public constant is a clean way to make characteristics of the instances known to client programmers • Programmers who use an object of a class are called client programmers • Public class data members are accessed by the syntax <class name>.<class data members>
Background image of page 2
Object Oriented Programming Java - Defining Own Classes R.B. Lenin Winter - 2006 DA-IICT 25 Information Hiding and Visibility Modifiers For example, if there is a maximum possible top speed of the MobileRobot class, we can make this information available to the client programmers as a class constant by declaring the class as Class MobileRobot { public static final double TOP_SPEED = 8.25; } A Client program can access this information as System.out.println(“The top speed is “ + MobileRobot.TOP_SPEED);
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object Oriented Programming Java - Defining Own Classes R.B. Lenin Winter - 2006 DA-IICT 26 Information Hiding and Visibility Modifiers Suppose a fee is automatically charged and deducted from the converted amount. Let the rate of charge is 5% of the exchange rate. public void setExchangeRate (double rate) { exchangeRate = rate; feeRate = rate*FEE_PERCENTAGE; } FEE_PERCENTAGE is a class constant whose value is set to 0.05 inside the class CurrencyConverter private static final double FEE_PERCENTAGE = 0.05;
Background image of page 4
Object Oriented Programming
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/15/2010 for the course CSE IT115 taught by Professor Rblenin during the Spring '10 term at Punjab Engineering College.

Page1 / 28

lecture-24 - Information Hiding and Visibility Modifiers...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online