|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

05-16-2008, 05:26 AM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 509
|
|
Im back!!!!
@ rjuyal, you have the correct guess,
@ eku, lacking....
actually it is compilable and runnable code....
There is a member here who asked about nested extending of abstract classes(i may be wrong of its term)... i doubt at first, bec i really don't use that kind of implementation, and i replied to him that experimental code.....
@ eranga,
all within the contructor test will first to execute before at the main method... you're right....
@Jesdisciple
you're correct too,
But I think the compiler would complain that "Class B cannot be found" or something to that effect.
the compiler will not complain....
Generally, any class that was extend at the main class(handler) can be invoked its method within the main class by "this" referencing....
Any abstract classes that was extended from other abstract class which extended also in the main class(handler), can be invoked its method directly to main class(handler)...
next quiz please?!!
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-16-2008, 05:29 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
|
|
|
But I think you should have compiler warning. Because you are accessing non-public types here, through a public. Isn't it?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 13, 2008)
|
|

05-16-2008, 05:37 AM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 509
|
|
|
no warnings at all....
because, if the said abstract classes were not specified as public or private, it will then set to the default(can access within the package)....
and obviously the abstract classes are together with the main class(test)
please correct me if i'm wrong,
you can test the code with -Xlint
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-16-2008, 05:49 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
|
|
Ok, I'm talking about this.
public class test extends B
Class B is not a public class, so you are exporting a non-public class here in a public class. Best thing to do is, define the test class with default modifiers. It's a fixable warning, generally we called it is.
It's better check this myself too on an IDE now. 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 13, 2008)
|
|

05-16-2008, 05:57 AM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 509
|
|
What's the result?!! 
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-16-2008, 06:23 AM
|
|
Senior Member
|
|
Join Date: May 2008
Location: Makati, Philippines
Posts: 174
|
|
|
@sukatoa. . . I was really confused on that question. ^_^ another lesson learned
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.
|
|

05-16-2008, 06:25 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
|
|
Originally Posted by sukatoa
What's the result?!! 
Nothing, there is a warning. But your code is still compiled and run perfectly. All about access modifiers level.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 13, 2008)
|
|

05-16-2008, 06:28 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 22
|
|
What's the result (output or compile/runtime error/exception) of this?
class B {
String value;
B(String value){
this.value = value;
}
public String toString(){
return value;
}
static void test(A<? extends Object> a){
a.set(new B("foo"));
System.out.println(a.get());
}
public static void main(String[] args){
A<B> a = new A<B>();
test(a);
}
}
class A<T> {
private T o;
void set(T o){
this.o = o;
}
T get(){
return o;
}
}
|
|

05-16-2008, 06:39 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
|
|
|
This is much simpler pal. Got the compile error.
It's all about set()
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 13, 2008)
|
|

05-16-2008, 06:40 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 22
|
|
|
Did you compile it, then?
|
|

05-16-2008, 06:46 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
|
|
|
Oh, I'm not compile it. It wont compile it, because set() on class A not extended, but in class B you tried it. So it wont compile.
Simply incompatible method signature found.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 13, 2008)
|
|

05-16-2008, 09:10 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
|
|
1st thing first
Class B should be declared as public to run this program
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-16-2008, 09:40 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
|
|
I think still you get the same warning. 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 13, 2008)
|
|

05-16-2008, 11:50 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
|
|
 why i don't get the notification
anyways which kinda warning?
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-16-2008, 12:19 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
|
|
Should be much similar to this.
set(extends object) in class A<extends object> cannot be applied to class B
I guess it should be. Why is that your Eclipse doesn't give such notifications. 
I'm not sure my NetBeans give it too. 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 13, 2008)
|
|

05-16-2008, 02:09 PM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
|
|
Why is that your Eclipse doesn't give such notifications
My Eclipse  will certainly give much more elaborated, correct, acceptable ( out of words, add from your side  ) warning. but i have not compiled it though,as the rule says 
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-17-2008, 05:59 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
|
|
Yes pal that's true. Even me never touch the IDE. I thought after answering you test it ans says that. Sorry if I say some annoying thing there.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 13, 2008)
|
|

05-25-2008, 08:31 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
|
|
Seems all are silent here. I don't want to be like that. So here I'm, 
public interface myInterface extends intOne, intTwo {
private float temp = 12.234F;
int addIntegers(int i, int j);
}
My question is, the above code is valid or not. Please don't compile it before answering. 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 13, 2008)
|
|

05-25-2008, 08:55 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
|
|
|
i guess all variables in interface should be public staic final, so it should not compile.
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-25-2008, 09:21 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
|
|
[Yep, it's right. Because interface body only can contain constant declarations only. And if you want that set of modifiers can be omitted.
Next quiz? 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 13, 2008)
| | |