Win a copy of Head First Android this week in the Android forum!

kishore Kumar Sangam

Ranch Hand
+ Follow
since Jul 03, 2007
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 kishore Kumar Sangam

Hi All,
Today, I passed my SCJP 1.5 with 76%.Thanks a lot for this group.
14 years ago
public class Strings extends foo{
//public abstract void doit();

class foo extends Strings{
protected foo(){

}
protected foo(String sd){

}
public int x;
public final String main(String args){
Strings str = new Strings();
System.out.println(str.new foo().x);
return args;
//Integer i = new Integer(null);
}
}

public static void main(String args[]){
Strings str = new Strings();
System.out.println(str.new foo().main("c"));
//Integer i = new Integer(null);
}
}
Sorry for the confusion and thanks for the help.







------------------------------------------

Too much of Analysis leads to Paralysis.
You are assigning a value to reference variable in the run method.

so i =1 means a.i=1;
Hi All,
Just a quick question,

1.The methods of Object Class clone() and finalise() have protected access whereas the others public. Any reason why??? I mean why not public for them too...
public class Strings {

Strings(){
new check();
System.out.println("Strings getting constructed");// WHY IS THIS LINE NOT BEING PRINTED.
// IF THIS CODE IS UNREACHABLE SO WHY ISN'T THE COMPILER ERRING.
}
public static void main(String args[]){
new check();
}

}

class check{
check(){
System.out.println("Check getting constructed");
}
}
Only final static Constants.

Remember Interface can implement another interface only.There is not chance of getting static only or final only variables. It only inherits or declares static final vars.
Hi Dude,
The sorted array will appear something like thing

Data 1 9 10 12 12
Pos index 0 1 2 3 4

Search Index -1 -2 -3 -4 -5

You are searching for element 13 and you will get -6 always.In this scenario you can never get -5.

Change the data to get -5.

1 8 17 20 38 [Unique elements]
Hi Dude,
The following points might be note worthy,

1.The right hand side <Type> has to be freezed.

for eg: List <Integer> x = new ArrayList<? extends Number> // Compile Time error <? extends> and <? super> cannot be used on the right hand side until unless the first level has been freezed.

i.e in your case

List<List<? extends Number>> a=new ArrayList<List<? extends Number>>();


The above code is trying to instantiate an ArrayList that holds A List of Objects that are sub-classes of Number or a Number Class. In this code snippet.

The First level is ArrayList(List) -- This Type has to be freezed at compile time.

The second Level is ArrayList(List(? extends Number))




2. ? extends - YOU CANNOT ADD ELEMNETS.

The above code is adding elements of type List at Level 1 but not ElEMNETS OF TYPE NUMBER to LEVEL 2.



3. ? super - YOU CAN ADD ELEMENTS AT YOUR RISK - COMPILER WARNINGS
Hi Mike,
I understand what you are trying to point out.There should be a compile time error "Variable already declared in class"(Inherits from the super class).

It makes sense when we override a method (redefine the action).But it doesn't make sense to redeclare a variable or place holder( we can re-assign a value).


But as per the compiler specifications,

This is something to do with the Scope of Variables and Members,

#1 If you are accessing the member using the reference of the parent, then Parent class member is invoked. (always look for nearest members, if not found then broaden the scope)

#2 If you are accessing the member using the reference of the Child, then the look for the Child Class first, if not available then for the parent class.

Moral of the Story : Always look for nearest members, if not found then broaden the scope.
What is the error you are getting? Please paste it?
14 years ago
Compile time - Syntax checks.
Run Time - Semantics Checks.
Hi Jepser,
My question is not on errors.It is on warnings, When you assign Non-Generic to Generic compiler warns you becoz it is dangerous. But the other way round the compiler dosen't.

My question is why it dosen't warn ? The above code snippet proves that the other way round can also be dangerous.

Thanks
Kishore
Hi Hassel,
If you analyze the code above

After assigning the generic to non-generic reference, I am adding objects that are not Integer type using the non-generic reference.

That is also dangerous rt!!!
Hi option 'c' is also right taking into consideration - performance in terms of responsiveness - not in terms of memory utilization.