0% found this document useful (0 votes)
4 views2 pages

3 Java Objects

In Java, objects are referenced by names that store memory addresses, and can be assigned a null value. The document discusses aliasing and dangling references, illustrating these concepts with examples involving a 'Student' class and a 'Car' class. It also explains parameter passing by reference, demonstrating how changes to an object in a method affect the original object.

Uploaded by

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

3 Java Objects

In Java, objects are referenced by names that store memory addresses, and can be assigned a null value. The document discusses aliasing and dangling references, illustrating these concepts with examples involving a 'Student' class and a 'Car' class. It also explains parameter passing by reference, demonstrating how changes to an object in a method affect the original object.

Uploaded by

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

Java Objects

- Object name in java is a reference


- references are used to store address
- A special value null can be assigned
Student t;

t=null;

t = new Student();

- Alias name can created

Student y=t;

(See memory diagram on board)


Dangling Reference

Student s= new Student("abc");


Student t=s;

.....................................
Parameter Passing
................................
Object as parameter

- parameter passing by reference


.....................................
Example 1
class Car{
String make;
String getMake() { return make;}
void setMake(String m){make=m;}

}
class ChangeCarMake{
static void changeMake(Car p){
p.setMake("Suzuki");
}

class Test {
public static void main(String o[]){
Car c1=new Car();
c1.setMake("Honda");
ChangeCarMake.changeMake(c1);
System.out.println(c1.getMake());

}
}

(See memory diagram on board)


...............................................

You might also like