Share on Google+Share on Google+

SCJP Module-1 Question-24

The Sample program given below will test your understanding about the abstract class in Java.

Given a sample code:

1    abstract class Shape {
2    private int x, y;

3    public void setValue(int x, int y) {
4    this.x = x;
5    this.y = y;

6    System.out.println(x+y);

7    class Test {
8    public static void main(String args) {
9    Shape s = new Shape();
10  s.setValue(1, 2);

What will be the result? Choose the correct option?

(A) Successful run and print 3.
(B) Runtime error.
(C) Compilation error at line no 1.
(D) Compilation error at line no 9 that cannot create instance.




Posted on: July 21, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null