Originally posted by preeti dengri:
please look at these ques---and what will the output be
1) what will this give if b1=b2=b3=b4=true
(b1 | b2 & b3 ^ b4) ??
2) class Z extends Y
{
String s="this";
void display(String s)
{
System.out.println("this" +s);
}
public static void main(String args[])
{
new Z();
}
Z()
{
super.display(s);
}
}
class Y
{
String s="super";
void display(String s)
{
System.out.println("super" +s);
}
}
first one true.precedence follows as &,^,| .so since b1 is true so u should directly conclude the answer to be true.
Now if b1 is not true then b2&b3 result in true and ^ing with b4 results in false and |ng with b1 results in true or false depending wether b1 is true or false
The second one will print superthis.
It is simple to understand.U are calling the function in superclass and passing the parameter s of the subclass.That shadows the parameter s in the superclass.To avoid that u can write the superclass print ststement as
void display(String s)
{
System.out.println("super" +this.s);
}
Check out the results.!!!