IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C++ Programming C# Programming Java Programming
Microbiology Biochemistry Biotechnology Biochemical Engineering
Civil Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

Java Programming - Declarations and Access Control - Discussion

@ : Home > Java Programming > Declarations and Access Control > General Questions - Discussion

Read more:

"Time and tide wait for none."
- Alexander Pope
12. 

class A 
{  
    protected int method1(int a, int b) 
    {
        return 0; 
    } 
}
Which is valid in a class that extends class A?

[A]. public int method1(int a, int b) {return 0; }
[B]. private int method1(int a, int b) { return 0; }
[C]. public short method1(int a, int b) { return 0; }
[D]. static protected int method1(int a, int b) { return 0; }

Answer: Option B

Explanation:

Option A is correct - because the class that extends A is just simply overriding method1.

Option B is wrong - because it can't override as there are less access privileges in the subclass method1.

Option C is wrong - because to override it, the return type needs to be an integer. The different return type means that the method is not overriding but the same argument list means that the method is not overloading. Conflict - compile time error.

Option D is wrong - because you can't override a method and make it a class method i.e. using static.


Jatin Chanchlani said: (Fri, Dec 30, 2011 06:19:10 PM)    
 
In case of method overriding, the return type of the overridding method must be the same or a subtype of the return type declared in the original method in the super class.

So in this case option C is also correct.

Snehal Phatangare said: (Sun, Nov 4, 2012 07:41:24 PM)    
 
NO. The return type of the overridding method cannot be a sub-type of the method over-ridden. The method signature has to be exactly the same.

Write your comments here:
Name *:     Email:


© 2008-2013 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!