Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged

Sp7 #183

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions 56 Miscellaneous/Cpp/Assigning_Objects.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package Cpp;

class Test{

int a, b;

void set_ab(int a, int b) {

this.a = a;
this.b = b;

}

void show_ab() {

System.out.println("a is " + a + "\n");
System.out.println("b is " + b + "\n");
}
}

public class Assigning_Objects {

public static void main(String[] args) {
// TODO Auto-generated method stub

Test ob1 = new Test();
Test ob2 = new Test();


ob1.set_ab(10, 20);
ob2.set_ab(0, 0);

System.out.println("ob1 before assignment: ");
ob1.show_ab();
System.out.println("ob2 before assignment: ");
ob2.show_ab();
System.out.println();
ob2 = ob1; // assign ob1 to ob2

System.out.println("ob1 after assignment: ");
ob1.show_ab();
System.out.println("ob2 after assignment: ");
ob2.show_ab();

System.out.println();

ob1.set_ab(-1, -1); // change ob1

System.out.println("ob1 after changing ob1: ");
ob1.show_ab();
System.out.println("ob2 after changing ob1: ");
ob2.show_ab();

}

}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.