Question

In: Computer Science

Java Question: Which of the following statements about the reference super is true? a) It must...

Java Question:

Which of the following statements about the reference super is true?

a)

It must be used every time a method from the superclass is called.

b)

It must be the last statement of the subclass constructor.

c)

It must be the first statement of the subclass constructor.

d)

It can only be used once in a program.

Solutions

Expert Solution

Only option C is correct

a) We do not need to explicity add super before the method invocation of the parent class. It is done automatically by the JVM. So, even if we do not write super.methodCall(), it will still work

Ex:

class A{
        public void test() {
     System.out.print("A");             
        }
}


class B extends A{
        public void test2() {
                test(); // super.test(); ----> Same thing
        }
        
        public static void main(String[] args) {
                B b = new B();
                b.test2();
        }
}



b)
It has to be the first statement, not the last. As, whenever object of child class is created, the constructor of parent class should run first before any code runs for child class.
Though we do not have to define super() explicitly, JVM does it for us, but in the actual code, it has to be the first statement.

Ex:


- If we try to add at last, we get this error



c) As explained above, it has to be the first statement. THIS IS RIGHT

d) We can use super at multiple places like -
- calling functions of parent class (Though Implicit)
- calling constructor of parent class.
- referring to variable of parent class


ONLY part C is right and I have explained why others are wrong


Kindly upvote if this helped


Related Solutions

Question 14. Which of the following statements is NOT true about the components of a vector?...
Question 14. Which of the following statements is NOT true about the components of a vector? Any vector can be resolved into rectangular components Any vector can be resolved into non-rectangular components Components are rectangular when a vector is resolved along mutually perpendicular axes Components are non-rectangular when a vector is resolved along axes forming 45 degree  None of the above   Question 15. Which of the following methods is more appropriate when adding more than two vector? Parallelogram method...
Question Which of the following are true statements about what happens in the design phase In...
Question Which of the following are true statements about what happens in the design phase In the design phase we specify the architecture, technical components, modules, interfaces and data In the design phase we are interested in how the system will be built Design take the analysis statement and adds to it In the design phase we construct the system Question The System Design is (Choose all correct answers) Group of answer choices The System Design is the process in...
QUESTION 1 Which of the following statements about the balanced scorecard approach is NOT true? The...
QUESTION 1 Which of the following statements about the balanced scorecard approach is NOT true? The four perspectives of the balanced scorecard revolve around measures of quality, productivity, efficiency and timeliness, and marketing success. The balanced scorecard approach requires looking at performance from four different but related perspectives: financial, customer, internal business, and learning and growth. The balanced scorecard approach integrates financial and non-financial performance measures. the balanced scorecard helps to keep management focused solely on a company's financial factors....
Question 1     Which of the following statements about the Chi Square statistic is NOT true?...
Question 1     Which of the following statements about the Chi Square statistic is NOT true? Chi Square squares the differences between observed and expected frequencies, thus inflating the true difference. Chi Square is not calculated from observed and expected frequencies. Chi Square is artificially inflated by sample size. Measures of association need to be on standardized scales with a 0 meaning no relationship and 1 meaning a perfect relationship. Chi square can be virtually any positive number. Question 2...
Which of the following statements about correlation are true?
4. Correlation basics Which of the following statements about correlation are true? Check all that apply Correlation is a numerical value between 1.1 and 2. The sign of the correlation indicates the strength or consistency of the linear relationship between two variables. A negative correlation means that two variables tend to change in opposite directions The correlation indicates the strength and the direction of the linear relationship between two variables If the correlation between two variables is 0, there is no clear linear relationship between the...
Which of the following statements about genetics is TRUE?
Which of the following statements about genetics is TRUE?  a. A mutation is any change in DNA that is harmful to an organism. b. Genetic disorders are always caused by the inheritance of recessive alleles. c. The red queen hypothesis proposes that asexual reproduction evolved in organisms to increase genetic variation, and therefore, improve resilience in ever-changing environments. d. Natural selection acts directly on the phenotype and indirectly on the genotype.
Question 10 (1 point) Which of the following statements is true about productivity growth? a The...
Question 10 (1 point) Which of the following statements is true about productivity growth? a The largest contributor of productivity growth is technological progress, which accounts for approximately 90% of it. b The size of the capital stock in the economy explains roughly 70% of productivity growth. More and better plant and equipment make workers more productive. c Education and training have a contribution to productivity growth of 15%, and economies of scale and resource allocation have a combined contribution...
Question 11 Which of the following statements is NOT true about dictionary-based virus detection? A.            This...
Question 11 Which of the following statements is NOT true about dictionary-based virus detection? A.            This method can detect a virus almost immediately. B.            This method scans applications and other files when they have access to your system. C.            The software must be updated to detect new viruses. D.            This method can detect viruses that it knows about and those it does not know about. Question 12 Antivirus programs can use the suspicious behavior method to monitor the behavior of...
Which of the following is NOT true about Income Statements? Question 2 options: Revenue recognition and...
Which of the following is NOT true about Income Statements? Question 2 options: Revenue recognition and the Matching Principle require the recognition of revenue in the time period for which the product or service has been substantially performed. Operating expenses flow the income statement in the period they are incurred, while capital spending is recorded on the balance sheet then depreciated. Nonrecurring items can distort reported earnings in a given period. Analysts only need to track reported income and earnings...
Question 10 Which of the following statements about biological nitrogen fixation is true? Answers: a. It...
Question 10 Which of the following statements about biological nitrogen fixation is true? Answers: a. It is a strictly aerobic process b. It is a strictly anaerobic process c. It is confined to symbiotic bacteria d. It is a process carried out by bacteria, fungi and algae e. It is a process exclusive to bacteria Question 11 Which of the following statements is true in relation to anaerobic digestion? Answers: a. Only animal wastes are suitable feedstocks b. It produces...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT