How to use super in java?

Asked

Viewed 640 times

0

I know the basics of super, but for example : If I have a class mae Person with attributes name, age and sex, and a class daughter Student with attributes course, enrollment and period, and a class daughter of Student who is called Scholarship, how do I have to put in super all attributes of Student and Person, super type (name, age, sex, course, enrollment, period)? Because I did it in a code but error. Can’t post because if I put all classes here will be very big and hard to understand D:

  • 1

    I’ve added some related questions in addition to the duplicate that might help you better understand the super

  • Conceptual language reference: https://answall.com/q/252765/64969

  • You wouldn’t put everything in the super. You’d put every attribute in the class it was declared in. So you would have the Stock Exchange Builder passing all attribute values Bolsista(nome,idade,sexo,curso,matricula,periodo), as there is no attribute to set, just calls the super (Student) to set the rest super(nome,idade,sexo,curso,matricula, periodo). Hence set the course, the enrollment and the period, and called the super (Person) to set the rest super(nome, idade).

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.