Given below the sample code :
class Superclass {
int i = 30;
public void function()
{
System.out.println("Superclass.function()");
}
Superclass()
{
function();
}
}
public class Subclass extends Superclass
{
int i = -1;
public static void main(String argv[])
{
Superclass b = new Subclass();
System.out.println(b.i);
b.function();
}
public void function()
{
System.out.println("Subclass.function()");
}
}
What will be the output of the following code ?
1. Subclass.function() Subclass.function()
2. Subclass.function() -1 Subclass.function()
3. Subclass.function() 30 Subclass.function()
4. Compile error
(30)
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.