Question

In: Computer Science

Identify which of the following statements will generate an error. If there is an error, which...

Identify which of the following statements will generate an error. If there is an error, which phase of compiler construction (if any) will be suitable to detect the following errors and why?

1. A function is defined with the same signature as the previous one.

2. A variable named ‘new’ is defined and initialized two times. Once in main function and second in a “for” loop inside main function.

3. A multi-line comment that starts but not ends.

4. The following assignment expression is made where “var” is of Boolean datatype. var=10;

5. A function named “func1” is defined as follows public abstract protected int func1(float x,int y){…}

6. A class named “demo_class” is defined that implements an interface “X” demo_class Class implements X{…}

7. A while loop is defined that runs infinitely.

8. A string constant that starts with an inverted comma but does not end.

9. The following do- while loop is created without any statement. int x=1; do{ }while(x>10)

10. An interface “Int1” is created that inherits another interface “Int2” and contains two variables as follows interface Int1 inherits Int2 { int var1, var2; }

Solutions

Expert Solution

1) Error
   It will generate error due to same signature of function .To avoid it the try method overloading .

-------------------------------------------------------------------------------------------------------------
2) No Error
   Everytime when new operator is called it will assign a new memory and that object is created .

--------------------------------------------------------------------------------------------------------------
3) Error
   In multiline comment the compiler should know that which part is commented in code otherwise it will skip all the parts from where the comment begins.
   To avoid it use */ at the end of the line where you want to stop the comment.

---------------------------------------------------------------------------------------------------------------
4)Error
   The var is of type Boolean and integer is assigned to it.So,type mismatch error will be generated .Boolean will contain only True and False.

------------------------------------------------------------------------------------------------------------------------
5) Error
   Abstract methods does not have body.It is just reference to derived class that when inherits the base class the derived class should implement the abstract method of base class.

-------------------------------------------------------------------------------------------------------------------------
6)Error
   It will generate a error because of demo_class Class implements X{…}.

“Class classname implements interfacename {}” is the correct syntax to implement a interface.

so the error would be resolved by

Class demo_class implements X{...}

------------------------------------------------------------------------------------------------------------------------
7)No Error
   It will stop execution when the system is haulted or the memory is full.

--------------------------------------------------------------------------------------------------------------------------------
8)Error
   The String is represented inside "" .So if the otherside " is not there then it will generate error of String literal is not properly closed by ";

------------------------------------------------------------------------------------------------------------------------------------------
9)No Error
   It will move once in the loop as it is do-while loop even if the condition of while is false.

--------------------------------------------------------------------------------------------------------------------------------------------------
10)Error
   Interface are extended or implemented.
   For class we use implements keyword to use the Interface.
   For Interface it use extends keyword to use the other interface.

   Class implements interface
   Interface extends other interface


Related Solutions

a. Identify which ofthe following statements are correct and which are not correct.Write a...
a. Identify which of the following statements are correct and which are not correct. Write a correct alternative statement for those which are not correct.I. it is more expensive to install fibre-optic cable because specialist training is necessaryii. routers are used to connect subnets on a LANiii. all traffic in a subnet passes through the default gatewayiv. a layer 3 switch provides routing using MAC addressesv. computers and/or other devices that are networked in a single physical location are said...
Identify which of the following statements is true and which is false. 1) _________   For a...
Identify which of the following statements is true and which is false. 1) _________   For a set of numerical data, if the mean is larger than the median, this is evidence of right-skew. 2) _________   Negative values of the standard deviation indicate that the set of values is even less dispersed than would be expected by chance alone. 3) _________   For a set of numerical data, if the mean and the median are of equal value, this is evidence of...
Which of the following statements is correct? A) Corporate taxation can generate tax savings to the...
Which of the following statements is correct? A) Corporate taxation can generate tax savings to the unlevered firm. Therefore, the optimal capital structure should be financed by equity entirely. B) Corporate taxation can generate tax saving to the levered firm. Therefore, the optimal capital structure should exclude debt to completely offset the tax liability. C) Corporate taxation can generate tax saving to the levered firm. Therefore, the optimal capital structure includes enough debt to completely offset the tax liability. D)...
Which of the following statements about lipids within a membrane is false? Enzymes called flippases generate...
Which of the following statements about lipids within a membrane is false? Enzymes called flippases generate membrane asymmetry. They rotate rapidly around their long axes. They flip-flop readily from one monolayer to the other. They rapidly exchange positions with one another within the plane of the membrane.
Each of the following pairs of null and alternative hypothesis has some error. Identify the error...
Each of the following pairs of null and alternative hypothesis has some error. Identify the error and explain how to fix it. H0: The average ‘freshness’ of an edible food arrangement is at least 3 hours H1: The average ‘freshness’ of an edible food arrangement is not 3 hours H0: The average ‘freshness’ of an edible food arrangement is more than 3 hours H1: The average ‘freshness’ of an edible food arrangement is less than 3 hours H0: The average...
Each of the following statements contains an error. Describe each error and explain why the statement...
Each of the following statements contains an error. Describe each error and explain why the statement is wrong. (a) If the residuals are all negative, this implies that there is a negative relationship between the response variable and the explanatory variable. (b) A strong negative relationship does not imply that there is an association between the explanatory variable and the response variable. (c) A lurking variable is always something that can be measured.
Identify which of the following statements is false    A. The Lifetime Exemption applies only to...
Identify which of the following statements is false    A. The Lifetime Exemption applies only to gifts given. B. Casualty or theft losses incurred during the administration of the estate are deductible on the estate tax return. C. The estate tax return is due, ignoring extensions, 9 months after the decedent's date of death.    Which of the following transactions constitutes a taxable gift made by Ellen, a widow, in the current year?       A. Ellen transfers $60,000 to a...
Identify each of the following experimental occurrences as contributing to systematic error “S”, random error “R”,...
Identify each of the following experimental occurrences as contributing to systematic error “S”, random error “R”, both types of error “B”, or neither (does not cause error) “N” Write the code letters S, R, B or N, as appropriate, in the space beside the phrase. ____ reading a meniscus from above the plane of the calibration mark ____ reading a meniscus in the plane of the calibration mark, but with limits of human visual acuity ____ transferring analyte solution from...
Identify and differentiate the regulation and methods ofdocumenting for the following: an error in charting,...
Identify and differentiate the regulation and methods of documenting for the following: an error in charting, a late entry, and an error that occurred regarding care for a client.
For the following statements, state the null and alternative hypotheses and identify which represents the claim....
For the following statements, state the null and alternative hypotheses and identify which represents the claim. Determine when a type I or type II error occurs for a hypothesis test of the claim. Determine whether the hypothesis test is left-tailed, right-tailed, or two-tailed, and explain your reasoning. Explain how you should interpret a decision that rejects the null hypothesis. Explain how you would interpret a decision that fails to reject the null hypothesis. a. It is reported that the number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT