8 תשובות
איזה שפה?
יש לי בגאווה
ממליץ מחלקה סטנדרטית, של person למשל. רוצה שאני אעלה את זה לגיט ואשלח קישור?
פשוט תעשה גוגל עצמים ומחלקות
וזה די פשוט אחי אם יש לך את התבנית של הפעולה בונה ושל איך שהמחלקה של העצם בנויה הכל טוב
וזה די פשוט אחי אם יש לך את התבנית של הפעולה בונה ושל איך שהמחלקה של העצם בנויה הכל טוב
שואל השאלה:
c#
c#
אנונימי
שואל השאלה:
^^^ כן אני אשמח שניצל תודה
^^^ כן אני אשמח שניצל תודה
אנונימי
יש לי בjava
הנה מחלקה לדוגמה.
using system;
namespace example
{
// define the person class
public class person
{
// properties
public string name { get; set; }
public int age { get; set; }
// constructor
public person(string name, int age)
{
name = name;
age = age;
}
// method to display person details
public void displaydetails()
{
console.writeline($"name: {name}, age: {age}");
}
// method to update person age
public void updateage(int newage)
{
if (newage > 0)
{
age = newage;
console.writeline($"age updated to: {age}");
}
else
{
console.writeline("invalid age provided.");
}
}
}
// main program to test the person class
class program
{
static void main(string[] args)
{
// create a new person object
person person = new person("john doe", 30);
// display person details
person.displaydetails();
// update the person's age
person.updateage(35);
// display updated person details
person.displaydetails();
}
}
}
using system;
namespace example
{
// define the person class
public class person
{
// properties
public string name { get; set; }
public int age { get; set; }
// constructor
public person(string name, int age)
{
name = name;
age = age;
}
// method to display person details
public void displaydetails()
{
console.writeline($"name: {name}, age: {age}");
}
// method to update person age
public void updateage(int newage)
{
if (newage > 0)
{
age = newage;
console.writeline($"age updated to: {age}");
}
else
{
console.writeline("invalid age provided.");
}
}
}
// main program to test the person class
class program
{
static void main(string[] args)
{
// create a new person object
person person = new person("john doe", 30);
// display person details
person.displaydetails();
// update the person's age
person.updateage(35);
// display updated person details
person.displaydetails();
}
}
}
באותו הנושא: