Java Programming - Declarations and Access Control - Discussion
Discussion Forum : Declarations and Access Control - Finding the output (Q.No. 1)
1.
What will be the output of the program?
class A
{
final public int GetResult(int a, int b) { return 0; }
}
class B extends A
{
public int GetResult(int a, int b) {return 1; }
}
public class Test
{
public static void main(String args[])
{
B b = new B();
System.out.println("x = " + b.GetResult(0, 1));
}
}
Answer: Option
Explanation:
The code doesn't compile because the method GetResult() in class A is final and so cannot be overridden.
Discussion:
18 comments Page 2 of 2.
Pooja said:
7 years ago
Method overridden means method already in superclass same method in subclass.
Kashi said:
8 years ago
Can you please tell higher precedence in java in case operator?
Ravi Kiran said:
10 years ago
Compilation fails. Final methods can't be overridden.
Komal said:
4 years ago
What if object calls its own method? Please explain.
Yogesh said:
1 decade ago
Won't method hiding will ocuur in this case?
Pankaj said:
9 years ago
Thank you all for explaining the concept.
Harish said:
1 decade ago
Final methods can't be overridden.
Vignesh said:
1 decade ago
What is overridden?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers