Identify the syntax errors in the following code segment. Select all that apply.
ID: 3723049 • Letter: I
Question
Identify the syntax errors in the following code segment. Select all that apply.
public class SonicScrewdriver extends Tool
{
int functions;
public static void addFunction()
{ functions += 1; }
public static abstract doAnything();
@Override
public void toString()
{ System.out.println(functions); }
}
declaration of class variable
addFunction header
adding one to variable
doAnything function header
@Override annotation
toString function header
Identify the syntax errors in the following code segment. Select all that apply.
public class SonicScrewdriver extends Tool
{
int functions;
public static void addFunction()
{ functions += 1; }
public static abstract doAnything();
@Override
public void toString()
{ System.out.println(functions); }
}
Answers:declaration of class variable
addFunction header
adding one to variable
doAnything function header
@Override annotation
toString function header
Explanation / Answer
Answer : (a) declaration of class variable, (d) doAnything function header, (e) @Override annotation
The class should be declared abstract as it as an abstract method.
The doAnything() function doesn't have a return type.
The toString() function is not overriding the predefined toString() function as the return type is diferent. SO, the annotation is wrong.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.