Question 1
The following code will give
1: class Test
2: {
3: void show()
4: {
5: System.out.println("non-static method in Test");
6: }
7: }
8: public class Q3 extends Test
9: {
10: static void show()
11: {
12: System.out.println("Overridden non-static method in Q3");
13: }
14:
15: public static void main(String[] args)
16: {
17: Q3 a = new Q3();
18: }
19: }
A) Compilation error at line 3.
B) Compilation error at line 10.
C) No compilation error, but runtime exception at line 3.
D) No compilation error, but runtime exception at line 10.
Answer : B
Explanation :
Showing posts with label extends. Show all posts
Showing posts with label extends. Show all posts
Friday, 9 March 2012
Monday, 9 January 2012
Threads in Java - 1
Creating threads
Threads are objects in the Java language. A thread can be defined by extending the java.lang.Thread class or by implementing the java.lang.Runnable interface. The run() method should be overridden and should have the code that will be executed by the new thread. This method must be public with a void return type and should not take any arguments.
Extending thread
If we need to inherit the behavior of the Thread class, we can have a subclass of it. In this case, the disadvantage is that you cannot extend
Labels:
extends,
implements,
JAVA,
java.lang.Runnable,
run(),
SCJP
Subscribe to:
Posts (Atom)