why here we are creating two different classes like Person and Person client . Is it possible to do it with a single class. Please clear this i am very much confused?
Doubt about different classes
Hi Amankat
Regarding your query, yes it is possible to do with a single class if the design is simple. However as we move to complex designs it can lead to difficult debugging of the code as it is a poor design method to keep everything in one class. The reason we have created two different classes is because we want to separate the thing that will be constant (Person class) and the thing that will be changing (client class). Whenever later we want to change the behaviour of our client functions, we need to make the changes only in the person client class, thus reducing the scope of error of changing things in the person class by mistake.
Stating more simply, we do not want to give the user any chance to change the things he is not supposed to change, like the person class, thus separating the client class from the person.
please tell me i am continuosly getting error.
what error are you getting can you please provide screenshots.
your initial question was about why creating two classes instead of one single class. I hope I have cleared that doubt
But sir how can we multiple classes on online programs because they don’t give option to create multiple classes
yes you can create multiple classes on online programs however you can have only class as public. I will share an example shortly of how this can be done
But rishabh sir don’t explain it please tell me sir how to create by taking example of person and person client
okay I will send code link of creating multiple classes.
class PersonClient {
void print(){
System.out.println("This is person client class");
}
}
class Person {
void print(){
System.out.println("This is person class");
}
}
public class Main {
public static void main(String args[]) {
PersonClient p1 = new PersonClient();
p1.print();
Person p2 = new Person();
p2.print();
}
}
Thanks sir its run fine.
sir please tell me from where can i learn these concepts of making a classes in a single page.
Because sir is not teaching this concept.
I used print function just to display both the classes are working in a single.java file.
You will learn about it during inheritance
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.