Computer Science, asked by batismarkalexi1344, 11 months ago

If a class inherits from another class, can the data and methods be declared again in inherited class?

Answers

Answered by rakeshchennupati143
0

Answer:

Yes, we can!

Explanation:

  • suppose we have 2 classes which are class_1 and class_2
  • and consider class_1 have 2 functions start() and stop() and 2 variables of int number,id
  • if you want same names in class_2 we can initialize same functions and same variables that we have initialized in class_1
  • so consider when class_1 is inherited to class_2
  • in class 2 we want the value of variable "number" that is in class_1 but if we use "number" without any keyword it takes the value that is defined in this class
  • so to that we can used a keyword called super if we want any in inheriting class from class which is being inherited we use super keyword

Syntax :

       super.number ------ gives you the values of number from the class_1

-----Hope this is useful to you mark brainliest if you liked my answer :)

Similar questions