Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to get the values from object ?

843785Nov 10 2008 — edited Nov 10 2008
hi everybody,

i am experimenting with oops concept. first have a look at these coding and then tell me this.

what do i have to do to get the value of an object created. i want to use the get method to get the name, food and quantity, without the use of the created object. i mean i want to make the process independent of how many objects i make so that i can find a value given the name of a person in the object.

when this is done, i want to use this to create filed of a specific doc format for each object created. now when we are using the get method i want to read whats on the object value .

Am i being clear or are thing very confusing, please let me know wht u think so i can clarify myself more.
public class obj {

	String name;
	String food;
	int quantity;
	
	public void set(String ndata, String fdata,int qdata )
	{
		this.name=ndata;
		this.food=fdata;
		this.quantity=qdata;
		
		
	}
	public  void get()
	{
		System.out.println( this.name+"  "+this.food+"  "+this.quantity);
	 
	}
	public static void main(String[] args) {
		obj obj1= new obj();
		obj1.set("varun", "burger", 2);
		
		obj obj2= new obj();
		obj1.set("roshan", "diet pepsi", 1);
		
		obj obj3= new obj();
		obj1.set("aman", "biryani", 2);
		
		obj2.get();
	}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 8 2008
Added on Nov 10 2008
27 comments
365 views