LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-28-2011, 06:34 AM   #1
whiteshark2012
LQ Newbie
 
Registered: Feb 2011
Posts: 8

Rep: Reputation: 0
Question java : object oriented , how it works and how to set the getter and setter ?


from the Question above , I dont have a good Idea about OOP

please , I have a peace of code the does not work

public class Computer {
protected String hostName;
private int IPAddress;

Computer(String h, int i){
this.hostName = h;
this.IPAddress = i;
}
public int getIPAddress(){
return IPAddress;
}
public void setIPAddress(int i){
IPAddress = i;
}
public String searchIP(string c){
this.computerName = c;
if (this.computerName=("localhost"))
return "the IP address is 127.0.0.1";
}



}
 
Old 02-28-2011, 11:01 AM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
If you're asking why it's not compiling, it's because a) you used "string" instead of String and b) you use "computerName" instead of "hostName" in searchIP().
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Object-oriented C memory leak MTK358 Programming 37 12-19-2009 04:51 PM
Object Oriented Programming in the Web entz Programming 8 08-04-2009 05:10 AM
object oriented advice in C++ xeon123 Programming 5 05-02-2007 09:20 AM
How to write a object oriented program using c ssg14j Programming 6 08-10-2005 09:56 AM
Object-Oriented Design Citizen Bleys Programming 2 02-11-2002 01:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration