Win a copy of Microservices Testing (Live Project) this week in the Spring forum!

Kalpesh Pandya

Greenhorn
+ Follow
since Oct 07, 2000
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kalpesh Pandya

Your System.out.println("Hello") is not in the finally block. I think it's typo. It should be
Finally {
System.out.println("Hello")
return 4;
}
Hi,
First of all instead of int t = 0, it should be int i = 0.
If it is so, you are right, what's the problem ???
in first statement: b=(t | | ((i++) ==0)), as t is true, i++ never get executed, so i remains 0. rest of it is simple.

Originally posted by Makarand Akdar:
Hi friends,
public class Child extends Base {

Child(int i) { test (); }

Child(float f) { this ((int)f); }

void test() {
System.out.println("Child.test()");
}

static public void main(String[] a) {
new Child(10.8f).test();
}
}
Select most appropriate answer.

a) Child.test()
Child.test()
b) Compilation Error: No default constructor ( constructor matching Base())
found in class Base.
c) Runtime Error: No default constructor ( constructor matching Base())
found in class Base.
d) Compilation Error: Cannot call this() from a constructor.
The Answer to this question in given as ...a)
Why does Child.test() print twice ?
-Thanks


test() is called twice.
1. Child(int i) { test (); }
2. new Child(10.8f).test();
Evaluate your expression from left to right and you will get your answer !
Hi manish,
If you remove private from the method f() than it will print 1 as output. Private methods cannot be overridden, as they are not visible to sub class. method f() in subclass has nothing to do with method f() in super class. So when g() of super class is calling f(), only method available in super class is f() with return 2.
Hope this will help you !
Correct me if I am wrong, because earlier explanation given by others to this question confused me a lot !
This Question was originally posted by Manish.
I don't know how to re-open already posted topic, so I am posting it again.
public class Tester {
public static void main(String[] args) {
System.out.println(new Sub().g());
}
private int f() {
return 2;
}
int g() {
return f();
}
}
class Sub extends Tester {
public int f() {
return 1;
}
}
I think output should be 1 but it is printing 2.
Methods can be overridden to be more public...then also ???
Please correct me !!!
Manish
I commented System.out.println from try block and keeps both the return statements (without comments), still it compiles cleanly. I think return statement in try block doesn't guaranteed to be executed always and so considered conditional/optional.
Hi,
if ++/-- operators are placed on the left of an expression, then the value of expression is modified before it takes part in the rest of operation (pre-increment / decrement). If they are placed on the right of an expression, original value of the expression is used in the calcualtion and ++/-- only gets evaluated after calculation.(post incr/decr)
Hope this helps !!
Thanks ! This surely helped me out !
Following code prints answer as -> 5,Sub. I can understand sub but not 5, would anybody explain why?
class Super
{ int index = 5;
public void printVal()
{ System.out.println( "Super" );
}
}
class Sub extends Super
{ int index = 2;
public void printVal()
{ System.out.println( "Sub" );
}
}
public class Runner
{ public static void main( String argv[] )
{ Super sup = new Sub();
System.out.print( sup.index + "," );
sup.printVal();
}
}
Thanks !! Its clear now.
I came across following question in one of the mock exam.
StringBuffer sb1 = new StringBuffer("xyz");
StringBuffer sb2= new StringBuffer("xyz");
String ss1 = "xyz";
System.out.println(sb1==sb2);
System.out.println(sb1.equals(sb2)); // 2nd
System.out.println(sb1.equals(ss1)); //3rd
Answer is false, false, false.
Anybody would help me out why 2nd and 3rd comparison results in false ?
I am bit confused. Why GC is not considering String pool ?