kinnu jemmy

Greenhorn
+ Follow
since Oct 08, 2001
Merit badge: grant badges
For More
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 kinnu jemmy


i think it can be done.
quote from api about FilterInuputStream.
A FilterInputStream contains some other input stream, which it uses as its basic source of data, possibly transforming the
data along the way or providing additional functionality.
File is not a subclass of InputStream.that is the reason.
hope this helps.
yes.

in this eg. apple contain both the methods.
see JLS chapter 9 for more info.
kinnu
see the thread http://www.javaranch.com/ubb/Forum24/HTML/013283.html.
this will give answer to ur question
kinnu
answer for ur first question.
consider the case :u include only line 1 &4 -----------------
what happens at the line4.u r creating an instance of class Fruit.at that time, instance variables of class Fruit are initialised.here a new fruit object is created at line 1.this instance creation again cause instance variable in the fruit class to initialised.this process continues until stack is overflowed.the creation of fruit object takes place continuously until stack overflows. that is why u get StackOverFlowException
hope this helps.
kinnu
consider this code.this is also from jls.
class Scope {
int x=10;
void meth() {
int x=x;//line1
System.out.println(x);
}
}
error: the variable x might not have been initialized.
why this code produces error?if the scope of x declared inside the method is after line 1,then the x in the RHS will be treated as the instance variable x. But here the x in the RHS is the local variable x declared in the line1 itself.that is why this code produces error.
hope now u understood the need for emphasizing "including its own initializer."
regards,
kinnu
only reference is copied.
in ur code ,o1=02;
means the value ot o2 is copied into the value of o1.what is the value of o2? It is the reference to the object.so after assignment o1 & o2 contain same value.ie,both points to the same object. here object contains an int var. i.
after assignment,both o1& o2 points to the same object with int var i=20.so no copying of source object takes place.
hope this helps.
kinnu
this is taken from JLS.
a narrowing primitive conversion may be used if all of the following conditions are satisfied:
1.The expression is a constant expression of type byte, short, char or int.
2.The type of the variable is byte, short, or char.
3.The value of the expression (which is known at compile time, because it is a constant expression) is representable in the type of the variable.
If the type of the expression cannot be converted to the type of the variable by a conversion permitted in an assignment context,
then a compile-time error occurs.
since all three conditions are met, narrowing conversion is possible in this case without explicit cast.
hope thid helps.
kinnu
an inner class is non static nested class.an inner class can be
local, anonymous or non static member class.
if the innerclass is non static member class enclosing scope is the outer class.
if the innerclass is local class(class inside method) then that method directly encloses the class.the class is also enclosed by the outerclass.so the enclosing scope is the method(in which the class is defined) as well as the outerclass.
hope this helps
kinnu.
hi bajwa,
yes. you are correct.
that is why while overriding methods in class,u don't need to add
any modifier.but in order to implement methods in interface u have to specify the modifier as public.
regards,
kinnu
hi jonatan,
even if the abstract keyword is not needed before the method declaration,if we add it, it won't cause compiletime error.
hi bajwa,
methods inside interface are implicitly public.so in order to implement the method in we must use an access modifier having same or more access than the method in the interface.default access modifier has less access than public.
In the former case,default access modifier is used for the method in class ABQuestion.so while overriding we can use default, public or protected modifier.that is why compilation gives no error.
hope it helps
correct me if i am wrong.
kinnu
hi jane,
thanks for ur reply.
kinnu
Hi all,
consider the code below
public class B {
B() throws Exception {}
{
if(true) throw new Exception();
}
}
when i compile this code ,it gives an error saying "must be caught or declared to be thrown .
according to my knowledge ,if we throw a checked exception in an instance initializer ,a compile time error will occur unless we catch it or explicitly declare it in throws clause of each constructor.here i declared it in the constructor.then why the error is coming?
please tell me where i went wrong?
kinnu
hi,
thanks for ur reply.
kinnu
Hi all,
The following is taken from JLS

anybody please tell whether the code is correct or wrong?
i think the code is wrong.
it produces compiletime error.(forward reference).
The order of evaluation is static initilisation,instance initialisation.when the first static block is executing,the variable x is not declared yet.so it should produce error.In the same way other codes also.
kinnu

[This message has been edited by kinnu jemmy (edited November 20, 2001).]