Which of these lines in the below-given code snippet will throw a compilation error when executed?code: abstract class Student { private abstract void marks(); // Line 1 abstract void calculate(); //Line 2 public void percentage(){} //Line 3 } public class School extends Student{ // Line 4 void calculate() { // Line 5 } } Line 1Line 2Line 3Line 4
Question
Which of these lines in the below-given code snippet will throw a compilation error when executed?code: abstract class Student { private abstract void marks(); // Line 1 abstract void calculate(); //Line 2 public void percentage(){} //Line 3 } public class School extends Student{ // Line 4 void calculate() { // Line 5 } } Line 1Line 2Line 3Line 4
Solution
The line that will throw a compilation error when executed is Line 1.
In Java, an abstract method cannot be private. The reason is that abstract methods are meant to be overridden in a subclass, and private methods cannot be accessed from a subclass, hence cannot be overridden.
So, the declaration of the abstract method 'marks()' as private in the abstract class 'Student' will result in a compilation error.
Similar Questions
Which of the following Java code snippets gives a compilation error?Group of answer choicesclass MyClass<T> { public void add(T item) { // ... }}class MyClass<T extends Number & Comparable<T>> { // ...}class MyClass<T super Number> { // ...}class MyClass<T extends String> { public void add(T item) { // ... }}
Observe the below code : abstract public class Account{ private int accountNumber; private String holderName; private double balance; public Account(int accountNumber, String holderName, double balance) { this.accountNumber = accountNumber; this.holderName = holderName; this.balance = balance; } }Identify the correct statements.Select one:a.Code compiles successfullyb.code will not compile, because abstract class cannot have a constructorc.code will not compile because the abstract class do not have abstract methods
The following code contains one compilation error, find it?public class Test { Test() { } // line 1 static void Test() { this(); } // line 2 public static void main(String[] args) { // line 3 Test(); // line 4 }}
What is the output of the following code? 1: public abstract class Whale { 2: public abstract void dive() {}; 3: public static void main(String[] args) { 4: Whale whale = new Orca(); 5: whale.dive(); 6: } 7: } 8: class Orca extends Whale { 9: public void dive(int depth) { System.out.println("Orca diving"); } 10: }*1 pointA. Orca divingB. The code will not compile because of line 2.C. The code will not compile because of line 8.D. The code will not compile because of line 9.E. The output cannot be determined from the code provided.
What is the Output of following Java Program?abstract class Demo{ public int a; Demo() { a = 10; } abstract public void set(); }class Test extends Demo{ final public void get() { System.out.println("a = " + a); } public static void main(String[] args) { Test obj = new Test(); obj.get(); }}Select one:a.Compile Time Errorb.a=10c.Runtime Exception
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.