Skip to Main Content
Java Programming by Pearson
book

Java Programming by Pearson

by Hari Mohan Pandey
May 2024
Intermediate to advanced content levelIntermediate to advanced
889 pages
37h 5m
English
Pearson India
Content preview from Java Programming by Pearson
160 • Java Programming
To access any of the fi eld or method the dot operator can be used. For example, to access num and
show in the earlier class example the following can be written:
demo dd=new demo();
dd.num=20;
dd.show();
7.2 PROGRAMMING EXAMPLES
/*PROG 7.1 DEMO OF CLASS VER 1 */
class demo
{
private int cx, cy;
void input(int x, int y)
{
cx = x;
cy = y;
}
void show()
{
System.out.println(“cx=” + cx);
System.out.println(“cy=” + cy);
}
}
class JPS2
{
public static void main(String args[])
{
demo d = new demo();
d.input(10, 20);
d.show();
}
}
OUTPUT:
cx=10
cy=20 1
Explanation: A class is created ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Programming, 1st Edition by Pearson

Java Programming, 1st Edition by Pearson

K. Rajkumar
Object Oriented Programming Through Java by Pearson

Object Oriented Programming Through Java by Pearson

Ramesh Vasappanavara, Anand Vasappanavara, Gautam Vasappanavara
Python Programming by Pearson

Python Programming by Pearson

S.Sridhar, J. Indumathi, V.M. Hariharan

Publisher Resources

ISBN: 9781299486539