#Can someone please explain OOP to me please. I am very confused about "Class"

15 messages · Page 1 of 1 (latest)

cobalt prawn
#

Hello, can someone explain to me what is Class in the OOP please.

stark flameBOT
#

This post has been reserved for your question.

Hey @cobalt prawn! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

astral kettle
#

a class is a blueprint for a thing

#

in programming we like to work with data. OOP creates a framework for working with and manipulating data.

cobalt prawn
# astral kettle a class is a blueprint for a thing

The part I dont ubderstand about the class is that why we use static and sometimes not? Sometimes I see people say "public name(){}" and sometimes "public name{}". I am very confused about this. Could you plesse explain it to me

#

Sometimes they use void and sometimes they dont use voif

#

Void

#

And there is no "Public" in some cases as well.

astral kettle
#

if you are confused why we have access modifiers I could explain that as well.

astral kettle
#

Here is an example of a static field in a class

#
public class Student {
    private int id;
    private static int idCounter = 0;
    private String name;
    private int age;


    public Student(String name, int age) {
        this.id = Student.idCounter++;
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return this.id;
    }
    public String getName() {
        return this.name;
    }
    public int getAge() {
        return this.age;
    }


    public String toString() {
        return String.format("%s is %d years old and has the id %d", this.name, this.age, this.id);
    }



    public static void main(String[] args) {
        Student student = new Student("Billy", 16);

        System.out.println(student);
    }

    
}
weak gladeBOT
#

There are 4 things that you are confusing:

  1. What is the Class in OOP
  2. What is static in Class
  3. Public keyword ```java
  4. “public name() {}” and sometimes “public name()”

Like the language in the real life, Java language describe the life into programing. So everything in Java language relate to the real life.

  1. The Class in real world is a group of people that have the same attributes and actions. So in Java, the Class is the same meaning like this, it is used to make a pattern of some object.
    Ex: In real world, we have RichPeople Class, they have the same attributes like: money, car,.. and actions like: makeMoney, buyCar, …. We can describe this in Java by RichPeople Class.

  2. The static in real word meaning: “staying in one place without moving, or not changing for a long time”. So in Java, static means “every object that belong to Class has the same static attributes or static actions”.
    Ex: The RichPeople Class have static attributes like MINIMUM_MONEY = “1m $”

  3. Public in real word meaning: “Every one can know public things”. So in Java, it means if a Class has public attributes or public actions, the Object of other Class can know about those. You must read more about this with the keyword: “access modifiers in Java”

  4. I think you have error syntax here, I think there are “public name(){}” and “public name()”. They are two type of method (or action) in Class and Interface. Once you understand Class and Interface, you should research them. And now, you don’t need to worry about it. ```

This message has been formatted automatically. You can disable this using /preferences.