0% found this document useful (0 votes)
5 views12 pages

Reference Variable

Uploaded by

Sojal Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views12 pages

Reference Variable

Uploaded by

Sojal Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Primitive Data Type: like boolean, char, int, short, byte, long, float and

double. They are predefined (already defined) in Java.


Non-Primitive Data Type : They are called reference data type because
they refer to objects. They are created by the programmer like String,
Array, classes, interfaces.
• Learn all primitive data types with features and range of values .
Access specifiers/ Modifiers
• The data members, class or methods which are not declared using

any access modifiers i.e. they are default access modifier , they are

accessible only within the same package (no matter whether it is in

sub class or non sub class).


Example
class Room class RoomArea
{
{
float len;
float breadth; p.s.v.m ( String args[ ])
}
{ float area;

Room room1 = new Room( );

area= room1.len * room1.breadth;

S.o.p (“Area=“ +area);

}
Example
class Room class RoomArea
{ private float len;
{ p.s.v.m ( String args[ ])
private float breadth;
void getdata ( float a, float b) { float area;
{
Room room1 = new Room( );
len= a; breadth=b;
} room1.getdata( 14, 10);
} Output: RoomArea1.java:14: error: len
has private access in Room area= room1.len * room1.breadth;
area= room1.len * room1.breadth;
^
RoomArea1.java:14: error: breadth has S. o. p (“Area=“ +area);
private access in Room
area= room1.len * room1.breadth;
}
^
Use of ‘this’
class Test
class Main {
{ private float len; public static void main(String[] args) {
private float breadth; Test test = new Test();
void getdata ( float len, float breadth)
// set value of private variables
{
this.len= len; this.breadth=breadth; test.getdata(1,2);
} // get value of private variables
public float getlen()
System.out.println("Length " + test.getlen());
{
return this.len;
System.out.println("Breadth " +
}
test.getbreadth());
public float getbreadth() }
{ }
return this.breadth;
}
Length 1.0
} Breadth 2.0
• The this keyword refers to the current object in a method or

constructor. The most common use of the ‘this’ keyword is to

eliminate the confusion between class attributes and parameters with

the same name (because a class attribute is shadowed by a method or

constructor parameter).
mybox is an instance of Box called ‘object’ . It has physical reality of
Box.

Every time we create an instance of a class, we are creating an object

that contains its own copy of each instance variable defined by the

class.

You might also like