S
S
Sergey Sergey2022-03-30 23:56:18
Java
Sergey Sergey, 2022-03-30 23:56:18

Is this code OOP?

public abstract class C {
    public void c(){
        System.out.println("Меня зовут");
    }
}

public class A extends C implements D{
    C c = new C() {};
    public void a(){
        System.out.print("Иванов ");
        System.out.println("Иван");
    }

    @Override
    public void d() {
        System.out.println("Я живу в большом городе");
    }
}

interface D {
    public void d();
}

public class B extends A{
    A a = new A();
    private int age;
    public void setage(int a){
        this.age = a;
    }
    public int getage(){
        return age;
        }
    
        public void b(){
        B b = new B();
        a.c();
        a.a();
        a.d();
        b.setage(20);
        System.out.println("Мне " + b.getage() + " лет");
    }
}

public class E {
    public static void main(String[] args) {
       B b = new B();
        b.b();
    }
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Orkhan, 2022-03-31
@Sergei1111

Good afternoon.
Is the code OOP - yes, it is. But as a colleague noted, it is worth working on it. Read about java naming convention.
There is also a good course at https://refactoring.guru/refactoring
Classes should have a clear name
class B extends A
Do not forget about camelCase
b.setage(20);
The public access modifier in the interface is superfluous

interface D {
    public void d();
}

You cannot instantiate an abstract class:
C c = new C();

V
Vasily Bannikov, 2022-03-30
@vabka

I can say for sure that the code is garbage, with such a naming.
By what principle is the code divided here?

J
Jacen11, 2022-03-31
@Jacen11

Is this code OOP?
yes, but this is not your merit, just an object-oriented language and makes the principles of OOP use
a lot of inaccuracies, it is better to master OOP in practice, or try to describe real objects through programming. For example ducks. What they are, what they can do. What if the duck is rubber? Etc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question