kamilla miesak

Ranch Hand
+ Follow
since Mar 06, 2001
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 kamilla miesak

I need to clarify one rule regarding static modifier.
One of the answers in Jxam says that "variables defined inside inner classes cannot be static unless the inner class itself is static". In the K. Mughal's book there is a table with an overview of classes and interfaces - it looks from it that both anonymous and local static classes define only non-static members. Who is right?
Thanks.
ok, so how come I would not get a compiler error on overriding a static method with another static method? The compiler does complain if you override static with non-static or vice versa.
Hi,
here is the code from one of the mock exams listed on this site. The answer to it is "D" - the code does not compile because "explicit casting is required on line 25". I was thinking that it wouldn't compile because static method is overridden by another static method, and from what I understand - that's not allowed.
Can someone clarify this for me?
Thanks!
What will happen if you compile/run the following code?
1: class Test
2: {
3: static void show()
4: {
5: System.out.println("Show method in Test class");
6: }
7: }
8:
9: public class Q2 extends Test
10: {
11: static void show()
12: {
13: System.out.println("Show method in Q2 class");
14: }
15: public static void main(String[] args)
16: {
17: Test t = new Test();
18: t.show();
19: Q2 q = new Q2();
20: q.show();
21:
22: t = q;
23: t.show();
24:
25: q = t;
26: q.show();
27: }
28: }
A) prints "Show method in Test class"
"Show method in Q2 class"
"Show method in Q2 class"
"Show method in Q2 class"
B) prints "Show method in Test class"
"Show method in Q2 class"
"Show method in Test class"
"Show method in Test class"
C) prints "Show method in Test class"
"Show method in Q2 class"
"Show method in Test class"
"Show method in Q2 class"
D) Compilation error.
I'm confused about one part of method overriding. I know that with method overriding the method in a subclass cannot be overridden to be more private and has to throw either the same exception as the parent method or a subclass of the exception. How about if it throws no exceptions at all even if the parent method indicates throwing an exception - would that overriding be valid?
Thanks,
Kamilla
Hi,
I have two questions regarding the examples taken from Marcus Green tutorial.
Re #1:
public class MyIf{
public static void main(String argv[]){
MyIf mi = new MyIf();
}
MyIf(){
boolean b = false;
if(b=false){
System.out.println("The value of b is"+b);
}
}
}
Why does this code compile but produces no output?
I thougth it would print "The value of b is false".
Re# 2
public class MySwitch{
public static void main(String argv[]){
MySwitch ms= new MySwitch();
ms.amethod();
}
public void amethod(){
char k=10;
switch(k){
default:
System.out.println("This is the default output");
break;
case 10:
System.out.println("ten");
break;
case 20:
System.out.println("twenty");
break;
}
}
}
Can someone explain the line: char k = 10;
How come it's legal?
Thanks a lot!
Hello,
I'm going over the mock exams on Dan Chisholm's web site. Below is the code for two different examples which are very similar and only one of them compiles. Part of Dan's explanation says that "The Java programming language uses the rule that the most specific method is chosen. The informal intuition is that one method declaration is more specific than another if any invocation handled by the first method could be passed on to the other one without a compile-time type error". Can someone explain this a little further?
Thanks!
//this one prints "BB"
class A {}
class B extends A {}
class C extends B {
static void m(A x, A y) {System.out.print("AA");}
static void m(A x, B y) {System.out.print("AB");}
static void m(B x, A y) {System.out.print("BA");}
static void m(B x, B y) {System.out.print("BB");}
public static void main(String[] args) {
C c = new C();
m(c, c);
}
}
//compiler error
class A {}
class B extends A {}
class C extends B {
static void m(A x, A y) {System.out.print("AA");}
static void m(A x, B y) {System.out.print("AB");}
static void m(B x, A y) {System.out.print("BA");}
static void m(B x, B y) {System.out.print("BB");}
static void m(A x, C y) {System.out.print("AC");}
public static void main(String[] args) {
C c = new C();
m(c, c);
}
}
Thanks guys, it did make it clearer for me.
Hello,
i don't understand why for the following question the answer is "Runtime Exception". I would think that the code will run fine. From what I understand for casting between classes, one of the two classes must be a subclass of another and it doesn't matter which one.
Thanks,
Kamilla
What will happen if you attempt to compile and run the following code?
class Base {}
class Sub extends Base {}
class Sub2 extends Base {}
public class CEx{
public static void main(String argv[]){
Base b=new Base();
Sub s=(Sub) b;
}
}
1) Compile and run without error
2) Compile time Exception
3) Runtime Exception
Hi,
i'm trying to use ProgressMonitorInputStream when loading a file. From what I understand the ProgressMonitorInputStream should pop up a dialog box informing the user that file is loading if the time to load exceeds 2 seconds (default value that can be changed and i've tried it already).
However even though it takes several seconds to open my file (i've confirmed it with System.currentTimeMillis()), the dialog box does not come up. I've been searching the Internet and Sun's knowledgebase, but so far no luck .
Has anybody encountered that problem before? Any ideas on how to fix it?
Thanks.
18 years ago
I have another question:
is there a way to get an offset within a specific line as oppose to an offset for an entire JTextArea. When I do:
int offset= JTextArea.getCaret().getDot();
int line = JTextArea.getLineOfOffset(offset);
I do get correct line numbers, but the offset of the last character from a previous line is being carried over to the next line and calculated continuosly for the entire document.
I've tried couple of ways to calculate it separately, but nothing worked so far.
Thank you
18 years ago
is there a way to make it work in 1.3?
I'm using GridBagLayout right now.
18 years ago