Java Message Passing

  1. Message Passing through Methods
  2. Message Passing through Constructors
  3. Pass Different Values in Java

Note
Here I am using,
OS : Linux (Ubuntu 12.04)
IDE : Eclipse Tool
Eclipse : Juno (Version 4.2.0)
Package : Default package

A. Message Passing through Methods


MsgPass_Methods.java

public class MsgPass_Methods {
 
	void displayInt(int x, int y) {
		
		int z = x + y;
		
		System.out.println("Int Value is : "+z);
	}
	
	void displayFloat(float x, float y) {
		
		float z = x * y;
		
		System.out.println("Float Value is : "+z);
	}
}
 
class MainClass {
	
	public static void main (String args[]) {
		
		MsgPass_Methods obj = new MsgPass_Methods();
		
		obj.displayInt(10, 20);
		
		obj.displayFloat((float)2.35, (float)5.89);
	}
}

Sample Output

Int Value is : 30
Float Value is : 13.841499




B. Message Passing through Constructors


MsgPass_Const.java

public class MsgPass_Const {
	
	MsgPass_Const(int x, int y) {
		
		int z = x + y;
		
		System.out.println("Int Value is : "+z);
	}
	
	MsgPass_Const(float x, float y) {
		
		float z = x * y;
		
		System.out.println("Float Value is : "+z);
	}
}
 
class MainClass {
	
	public static void main(String args[]) {
		
		MsgPass_Const obj1 = new MsgPass_Const(5, 10);
		MsgPass_Const obj2 = new MsgPass_Const((float)12.23, (float)11.23);
	}
}

Sample Output

Int Value is : 15
Float Value is : 137.3429




C. Pass Different Values in Java


MsgPass_Diff.java

public class MsgPass_Diff {
	
	MsgPass_Diff(String str) {
		
		System.out.println(str);
	}
 
	void display1(int x, float y) {
		
		float z = x * y;
		
		System.out.println("The Value is : "+z);
	}
}
 
class MainClass {
	
	public static void main(String args[]) {
		
		MsgPass_Diff obj = new MsgPass_Diff("Message Passing !!!");
		
		obj.display1(10, (float) 23.48);
	}
}

Sample Output

Message Passing !!!
The Value is : 234.79999






SHARE THIS PAGE



product 2

product 3

Feedbacks : balaji.scz@gmail.com