SlideShare a Scribd company logo
1 of 68
Download to read offline
SCJP 1.6 (CX-310-065 , CX-310-066)

Subject: Object Orientation
           Overloading , overriding , encapsulation, constructor, polymorphism, is-a , has-a relations

Total Questions : 66

Prepared by : http://www.javacertifications.net



SCJP 6.0: Object Orientation
Questions Question - 1
What is the output for the below code ?

1. public class Test{
2. public static void main (String[] args) {
3.      Test t1 = new Test();
4.      Test t2 = new Test();
5.      if(t1.equals(t2)){
6.          System.out.println("equal");
7.      }else{
8.          System.out.println("Not equal");
9.      }
10. }
11. }

1.Not equal
2.equal
3.Compilation fails due to an error on line 5 - equals method not defind in Test class
4.Compilation fails due to an error on lines 3 and 4
resposta
Explanation :
A is the correct answer.

Every class in Java is a subclass of class Object, and Object class has equals method.
In Test class equals method is not implemented. equals method of Object class only
check for reference so return false in this case. t1.equals(t1) will return true.



Question - 2
What is the output for the below code ?

1. public class Test{
2. public static void main (String[] args) {
3.      Test t1 = new Test();
4.      Test t2 = new Test();
5.     if(t1 instanceof Object){
6.          System.out.println("equal");
7.      }else{
8.          System.out.println("Not equal");
9.      }
10. }
11. }
1.Not equal
2.equal
3.Compilation fails due to an error on line 5
4.Compilation fails due to an error on lines 3 and 4

Explanation :
B is the correct answer.

Every class in Java is a subclass of class Object, so every object is instanceof Object.



Question - 3
What is the output for the below code ?

public class A {
    public void printValue(){
        System.out.println("Value-A");
    }
}

public class B extends A{
    public void printName(){
        System.out.println("Name-B");
    }
}

1. public class Test{
2. public static void main (String[] args) {
3.      B b = new B();
4.      b.printName();
5.      b.printValue();
6. }
7. }

1.Value-A Name-B
2.Name-B Value-A
3.Compilation fails due to an error on line 5
4.Compilation fails due to an error on lines 4

Explanation :
B is the correct answer.

Class B extended Class A therefore all methods of Class A will be available to class B
except private methods.



Question - 4
What is the output for the below code ?

public    class A {
public void printValue(){
         System.out.println("Value-A");
     }
}

public class B extends A{
    public void printNameB(){
        System.out.println("Name-B");
    }
}

public class C extends A{

     public void printNameC(){
         System.out.println("Name-C");
     }

}

1. public class Test{
2. public static void main (String[] args) {
3.      B b = new B();
4.      C c = new C();
5.      newPrint(b);
6.      newPrint(c);
7. }
8. public static void newPrint(A a){
9.      a.printValue();
10. }
11. }

1.Value-A Name-B
2.Value-A Value-A
3.Value-A Name-C
4.Name-B Name-C

Explanation :
B is the correct answer.

Class B extended Class A therefore all methods of Class A will be available to class B
except private methods. Class C extended Class A therefore all methods of Class A
will be available to class C except private methods.



Question - 5
What is the output for the below code ?

public class A1 {
    public void printName(){
        System.out.println("Value-A");
    }
}

public class B1 extends A1{
    public void printName(){
System.out.println("Name-B");
     }
}


public class Test{
    public static void main (String[] args) {
        A1 b = new B1();
        newPrint(b);
    }
    public static void newPrint(A1 a){
        a.printName();
    }
}

1.Value-A
2.Name-B
3.Value-A Name-B
4.Compilation fails

Explanation :
B is the correct answer.

This is an example of polymophism.When someone has an A1 reference that NOT
refers to an A1 instance, but refers to an A1 subclass instance, the caller should be
able to invoke printName() on the A1 reference, but the actual runtime object (B1
instance) will run its own specific printName() method. So printName() method of B1
class executed.



Question - 6
What is the output for the below code ?

public class A {
    public void printName(){
        System.out.println("Value-A");
    }
}

public class B extends A{
    public void printName(){
        System.out.println("Name-B");
    }
}

public class C extends A{

     public void printName(){
         System.out.println("Name-C");
     }

}

1. public class Test{
2. public static void main (String[] args) {
3.        A b = new B();
4.        C c = new C();
5.        b = c;
6.        newPrint(b);
7.    }
8.    public static void newPrint(A a){
9.        a.printName();
10.   }
11.   }

1.Name-B
2.Name-C
3.Compilation fails due to an error on lines 5
4.Compilation fails due to an error on lines 9

Explanation :
B is the correct answer.

Reference variable can refer to any object of the same type as the declared reference
OR can refer to any subtype of the declared type. Reference variable "b" is type of
class A and reference variable "c" is a type of class C but reference variable "c" is a
subtype of A class. So it works properly.



Question - 7
What is the output for the below code ?

public class A {
    public void printName(){
        System.out.println("Value-A");
    }
}

public class B extends A{
    public void printName(){
        System.out.println("Name-B");
    }
}

public class C extends A{

      public void printName(){
          System.out.println("Name-C");
      }

}

1. public class Test{
2. public static void main (String[] args) {
3.      B b = new B();
4.      C c = new C();
5.      b = c;
6.      newPrint(b);
7. }
8. public static void newPrint(A a){
9.        a.printName();
10. }
11. }

1.Name-B
2.Name-C
3.Compilation fails due to an error on lines 5
4.Compilation fails due to an error on lines 9

Explanation :
C is the correct answer.

Reference variable can refer to any object of the same type as the declared reference
OR can refer to any subtype of the declared type. Reference variable "b" is type of
class B and reference variable "c" is a type of class C. So Compilation fails.



Question - 8
What is the output for the below code ?

public class C {

}

public class D extends C{

}

public class A {

     public C getOBJ(){
         System.out.println("class A - return C");
         return new C();

     }

}

public class B extends A{

     public D getOBJ(){
         System.out.println("class B - return D");
         return new D();

     }

}

public class Test {

public static void main(String... args) {
     A a = new B();
     a.getOBJ();

      }
}

1.class A - return C
2.class B - return D
3.Compilation fails
4.Compilation succeed but no output

Explanation :
B is the correct answer.

From J2SE 5.0 onwards. return type in the overriding method can be same or subtype
of the declared return type of the overridden (superclass) method.



Question - 9
What is the output for the below code ?

public class B {

     public String getCountryName(){
         return "USA";
     }

     public StringBuffer getCountryName(){
         StringBuffer sb = new StringBuffer();
         sb.append("UK");
         return sb;
     }


     public static void main(String[] args){
         B b = new B();
         System.out.println(b.getCountryName().toString());
     }

}

1.USA
2.Compile with error
3.UK
4.Compilation succeed but no output

Explanation :
B is the correct answer.

Compile with error : You cannot have two methods in the same class with signatures
that only differ by return type.



Question - 10
What is the output for the below code ?

public class A1 {
    public void printName(){
        System.out.println("Value-A");
    }
}

public class B1 extends A1{
    protected void printName(){
        System.out.println("Name-B");
    }
}


public class Test{
    public static void main (String[] args) {
        A1 b = new B1();
        newPrint(b);
    }
    public static void newPrint(A1 a){
        a.printName();
    }
}

1.Value-A
2.Name-B
3.Value-A Name-B
4.Compilation fails

Explanation :
D is the correct answer.

The access level can not be more restrictive than the overridden method's.
Compilation fails because of protected method name printName in class B1.



Question - 11
What is the output for the below code ?

public class A {
    private void printName(){
        System.out.println("Value-A");
    }
}

public class B extends A{
    public void printName(){
        System.out.println("Name-B");
    }
}


public class Test{
    public static void main (String[] args) {
        B b = new B();
b.printName();
     }

}

1.Value-A
2.Name-B
3.Value-A Name-B
4.Compilation fails - private methods can't be override

Explanation :
B is the correct answer.

You can not override private method , private method is not availabe in subclass . In
this case printName() method a class A is not overriding by printName() method of
class B. printName() method of class B different method. So you can call printName()
method of class B.



Question - 12
What is the output for the below code ?

public class A {
    private void printName(){
        System.out.println("Value-A");
    }
}

public class B extends A{
    public void printName(){
        System.out.println("Name-B");
    }
}


1. public class Test{
2. public static void main (String[] args) {
3.      A b = new B();
4.      b.printName();
5. }
6. }

1.Value-A
2.Compilation fails due to an error on lines 4
3.Name-B
4.Compilation fails - private methods can't be override

Explanation :
B is the correct answer.

You can not override private method , private method is not availabe in subclass .
printName() method in class A is private so compiler complain about b.printName() .
The method printName() from the type A is not visible.
Question - 13
What is the output for the below code ?

import java.io.FileNotFoundException;

public class A {
    public void printName() throws FileNotFoundException {
        System.out.println("Value-A");
    }
}

public class B extends A{
    public void printName() throws Exception{
        System.out.println("Name-B");
    }
}


public class Test{
    public static void main (String[] args) throws Exception{
        A a = new B();
        a.printName();
    }

}

1.Value-A
2.Compilation fails-Exception Exception is not compatible with throws clause in
A.printName()
3.Name-B
4.Compilation succeed but no output

Explanation :
B is the correct answer.

Subclass overriding method must throw checked exceptions that are same or subclass
of the exception thrown by superclass method.



Question - 14
What is the output for the below code ?

import java.io.FileNotFoundException;

public class A {
    public void printName() throws FileNotFoundException {
        System.out.println("Value-A");
    }
}

public class B extends A{
    public void printName() throws NullPointerException{
System.out.println("Name-B");
     }
}


public class Test{
    public static void main (String[] args) throws Exception{
        A a = new B();
        a.printName();
    }

}

1.Value-A
2.Compilation fails-Exception NullPointerException is not compatible with throws
clause in A.printName()
3.Name-B
4.Compilation succeed but no output

Explanation :
C is the correct answer.

The overriding method can throw any unchecked (runtime) exception, regardless of
exception thrown by overridden method. NullPointerException is RuntimeException
so compiler not complain.



Question - 15
What is the output for the below code ?

public class A {
    public static void printName() {
        System.out.println("Value-A");
    }
}

public class B extends A{
    public void printName(){
        System.out.println("Name-B");
    }
}



public class Test{
    public static void main (String[] args) throws Exception{
        A a = new B();
        a.printName();
    }

}

1.Value-A
2.Compilation fails-This instance method cannot override the static method from A
3.Name-B
4.Compilation succeed but no output

Explanation :
B is the correct answer.

You cannot override a static method . Compilation fails-This instance method cannot
override the static method from A.



Question - 16
What is the output for the below code ?

public class A {
    public A(){
        System.out.println("A");
    }
    public A(int i){
        this();
        System.out.println(i);
    }
}


public class B extends A{
    public B (){
        System.out.println("B");
    }
    public B (int i){
        this();
        System.out.println(i+3);
    }
}


public class Test{

     public static void main (String[] args){
         new B(5);
     }
}

1.A B 8
2.A 5 B 8
3.A B 5
4.B 8 A 5

Explanation :
A is the correct answer.

Constructor of class B call their superclass constructor of class A (public A()) , which
execute first, and that constructors can be overloaded. Then come to constructor of
class B (public B (int i)).
Question - 17
What is the output for the below code ?

public class A {
    public A(){
        System.out.println("A");
    }
    public A(int i){
        System.out.println(i);
    }
}


public class B extends A{
    public B (){
        System.out.println("B");
    }
    public B (int i){
        this();
        System.out.println(i+3);
    }
}


public class Test{

     public static void main (String[] args){
         new B(5);
     }
}

1.A B 8
2.A 5 B 8
3.A B 5
4.B 8 A 5

Explanation :
A is the correct answer.

Constructor of class B call their superclass constructor of class A (public A()) , which
execute first, and that constructors can be overloaded. Then come to constructor of
class B (public B (int i)).



Question - 18
What is the output for the below code ?

public class A {
    public final void printName() {
        System.out.println("Value-A");
    }
}
public class B extends A{
    public void printName(){
        System.out.println("Name-B");
    }
}



public class Test{
    public static void main (String[] args) throws Exception{
        A a = new B();
        a.printName();
    }

}

1.Value-A
2.Compilation fails-Cannot override the final method from A
3.Name-B
4.Compilation succeed but no output

Explanation :
B is the correct answer.

You cannot override a final method. Compilation fails-Cannot override the final
method from A.



Question - 19
What is the output for the below code ?

public class A {
    public void printName() {
        System.out.println("Value-A");
    }
}

public class B extends A{
    public void printName(){
        System.out.println("Name-B");
        super.printName();
    }
}



public class Test{
    public static void main (String[] args) throws Exception{
        A a = new B();
        a.printName();
    }

}
1.Value-A
2.Name-B Value-A
3.Name-B
4.Value-A Name-B

Explanation :
B is the correct answer.

super.printName(); calls printName() method of class A.



Question - 20
What is the output for the below code ?

public class A {
    public void printName() {
        System.out.println("Name-A");
    }

}

public class B extends A{
    public void printName(){
        System.out.println("Name-B");

     }

     public void printValue() {
         System.out.println("Value-B");
     }

}



1. public class Test{
2. public static void main (String[] args){
3.      A b = new B();
4.      b.printValue();
5. }
6. }

1.Value-B
2.Compilation fails due to an error on lines 4
3.Name-B
4.Value-B Name-B

Explanation :
B is the correct answer.

You are trying to use that A reference variable to invoke a method that only class B
has. The method printValue() is undefined for the type A. So compiler complain.
Question - 21
What is the output for the below code ?

public class A {
    public void printName() {
        System.out.println("Name-A");
    }

}

public class B extends A{
    public void printName(){
        System.out.println("Name-B");

     }

     public void printValue() {
         System.out.println("Value-B");
     }

}



1. public class Test{
2. public static void main (String[] args){
3.      A a = new A();
4.      B b = (B)a;
5.      b.printName();
6. }
7. }

1.Value-B
2.Compilation fails due to an error on lines 4
3.Name-B
4.Compilation succeed but Runtime Exception

Explanation :
D is the correct answer.

java.lang.ClassCastException: A cannot be cast to B . You can cast subclass to
superclass but not superclass to subclass.upcast is ok. You can do B b = new B(); A a
= (A)b;



Question - 22
What is the output for the below code ?

public class A {
    public void printName() {
        System.out.println("Name-A");
    }
}

public class B extends A{
    public void printName(){
        System.out.println("Name-B");

     }

     public void printValue() {
         System.out.println("Value-B");
     }

}



1. public class Test{
2. public static void main (String[] args){
3.      B b = new B();
4.      A a = (A)b;
5.      a.printName();
6. }
7. }

1.Value-B
2.Compilation fails due to an error on lines 4
3.Name-B
4.Compilation succeed but Runtime Exception

Explanation :
C is the correct answer.

You can cast subclass to superclass but not superclass to subclass.upcast is ok.
Compile clean and output Name-B.



Question - 23
Which of the following statement is true ?

1.A class can implement more than one interface.
2.An interface can extend another interface.
3.All variables defined in an interface implicitly public, static, and final.
4.All of the above statements are true

Explanation :
D is the correct answer.

All of the above statements are true.



Question - 24
What is the output for the below code ?

1. public interface InfA {
2.      protected String getName();
3. }

public class Test implements InfA{
    public String getName(){
        return "test-name";
    }

     public static void main (String[] args){
         Test t = new Test();
         System.out.println(t.getName());

     }
}

1.test-name
2.Compilation fails due to an error on lines 2
3.Compilation fails due to an error on lines 1
4.Compilation succeed but Runtime Exception

Explanation :
B is the correct answer.

Illegal modifier for the interface method InfA.getName(); only public and abstract are
permitted



Question - 25
What is the output for the below code ?

public class A {
    public void printName() {
        System.out.println("Name-A");
    }
}

1. public class B extends A{
2. public String printName(){
3.      System.out.println("Name-B");
4.      return null;
5. }
6. }

public class Test{
    public static void main (String[] args){
        A a = new B();
        a.printName();

     }
}

1.Name-B
2.Compilation fails due to an error on lines 2
3.Name-A
4.Compilation fails due to an error on lines 4

Explanation :
B is the correct answer.

printName() method of class A and printName() method of class B has different
return type. So printName() method of class B does not overriding printName()
method of class A. But class B extends A so printName() method of class A is
available in class B, So compiler complain about the same method name. Method
overloading does not consider return types.



Question - 26
What is the output for the below code ?

public class D {
    int i;
    int j;
    public D(int i,int j){
        this.i=i;
        this.j=j;
    }

     public void printName() {
         System.out.println("Name-D");
     }

}

1. public class Test{
2. public static void main (String[] args){
3.      D d = new D();
4.      d.printName();
5.
6. }
7. }

1.Name-D
2.Compilation fails due to an error on lines 3
3.Compilation fails due to an error on lines 4
4.Compilation succeed but no output

Explanation :
B is the correct answer.

Since there is already a constructor in this class (public D(int i,int j)), the compiler
won't supply a default constructor. If you want a no-argument constructor to overload
the with-arguments version you already have, you have to define it by yourself. The
constructor D() is undefined in class D. If you define explicit constructor then default
constructor will not be available. You have to define explicitly like public D(){ } then
the above code will work. If no constructor into your class , a default constructor will
be automatically generated by the compiler.



Question - 27
What is the output for the below code ?

public class D {
    int i;
    int j;
    public D(int i,int j){
        this.i=i;
        this.j=j;
    }

     public void printName() {
         System.out.println("Name-D");
     }

     public D(){

     }

}

1. public class Test{
2. public static void main (String[] args){
3.      D d = new D();
4.      d.printName();
5.
6. }
7. }

1.Name-D
2.Compilation fails due to an error on lines 3
3.Compilation fails due to an error on lines 4
4.Compilation succeed but no output

Explanation :
A is the correct answer.

The constructor D() is defined in class D. If you define explicit constructor then
default constructor will not be available. You have to define explicitly like public D()
{}.



Question - 28
Which of the following statement is true about constructor?

1.The constructor name must match the name of the class.
2.Constructors must not have a return type.
3.The default constructor is always a no arguments constructor.
4.All of the above statements are true

Explanation :
D is the correct answer.

All of the above statements are true.



Question - 29
What is the output for the below code ?

1. public class A {
2. int i;
3. public A(int i){
4.      this.i=i;
5. }
6. public void printName(){
7.      System.out.println("Name-A");
8. }
9. }

10. public class C extends A{
11. }

12.   public class Test{
13.   public static void main (String[] args){
14.       A c = new C();
15.       c.printName();
16.   }
17.   }

1.Name-A
2.Compilation fails due to an error on lines 10
3.Compilation fails due to an error on lines 14
4.Compilation fails due to an error on lines 15

Explanation :
B is the correct answer.

Implicit super constructor A() is undefined for default constructor. Must define an
explicit constructor. Every constructor invokes the constructor of its superclass
implicitly. In this case constructor of class A is overloaded. So need to call explicitly
from subclass constructor. You have to call superclass constructor explicitly . public
class C extends A{ public C(){ super(7); } }



Question - 30
What is the output for the below code ?

public    class A {
public A(){
         System.out.println("A");
     }
}

public class B extends A{
    public B(){
        System.out.println("B");
    }
}

public class C extends B{
    public C(){
        System.out.println("C");
    }
}

public class Test{
    public static void main (String[] args){
        C c = new C();
    }
}

1.A B C
2.C B A
3.C A B
4.Compilation fails

Explanation :
A is the correct answer.

Every constructor invokes the constructor of its superclass implicitly. Superclass
constructor executes first then subclass constructor.



Question - 31
What is the output for the below code ?

public    class A {

     public A(int i){
         System.out.println(i);
     }

}

1. public class B extends A{
2. public B(){
3.      super(6);
4.      this();
5. }
6. }

public class Test{
    public static void main (String[] args){
B b = new B();
     }
}

1.6
2.0
3.Compilation fails due to an error on lines 3
4.Compilation fails due to an error on lines 4

Explanation :
D is the correct answer.

A constructor can NOT have both super() and this(). Because each of those calls must
be the first statement in a constructor, you can NOT use both in the same constructor.



Question - 32
What is the output for the below code ?

1. public class A {
2. public A(){
3.      this(8);
4. }
5. public A(int i){
6.      this();
7. }
8. }


public class Test{
    public static void main (String[] args){
        A a = new A();
    }
}

1.8
2.0
3.Compilation fails due to an error on lines 1
4.Compilation fails due to an error on lines 3

Explanation :
D is the correct answer.

This is Recursive constructor invocation from both the constructor so compiler
complain.



Question - 33
What is the output for the below code ?
1. public class Test {
2. static int count;
3. public Test(){
4.      count = count +1 ;
5. }
6. public static void main(String argv[]){
7.      new Test();
8.      new Test();
9.      new Test();
10.     System.out.println(count);
11. }
12. }

1.3
2.0
3.1
4.Compilation fails due to an error on lines 2

Explanation :
A is the correct answer.

static variable count set to zero when class Test is loaded. static variables are related
to class not instance so count increases on every new Test();



Question - 34
public class A {
    public void test1(){
        System.out.println("test1");
    }
}

public class B extends A{
    public void test2(){
        System.out.println("test2");
    }
}

1. public class Test{
2. public static void main (String[] args){
3.      A a = new A();
4.      A b = new B();
5.      B b1 = new B();
6.      // insert code here
7. }
8. }

Which of the following , inserted at line 6, will compile and print
test2?

1.((B)b).test2();
2.(B)b.test2();
3.b.test2();
4.a.test2();
Explanation :
A is the correct answer.

((B)b).test2(); is proper cast. test2() method is in class B so need to cast b then only
test2() is accessible. (B)b.test2(); is not proper cast without the second set of
parentheses, the compiler thinks it is an incomplete statement.



Question - 35
What is the output for the below code ?

public class A {
    static String str = "";
    protected A(){
        System.out.println(str + "A");
    }
}

public class B extends A{
    private B (){
        System.out.println(str + "B");
    }
}


1. public class Test extends A{
2. private Test(){
3.      System.out.println(str + "Test");
4. }
5. public static void main (String[] args){
6.      new Test();
7.      System.out.println(str);
8. }
9. }

1.A Test
2.A B Test
3.Compilation fails due to an error on lines 6
4.Compilation fails due to an error on lines 2

Explanation :
A is the correct answer.

Test class extends class A and there is no attempt to create class B object so private
constructor in class B is not called . private constructor in class Test is okay. You can
create object from the class where private constructor present but you can't from
outside of the class.



Question - 36
public class A{
 private void test1(){

          System.out.println("test1 A");
     }
}


public class B extends A{
public void test1(){

     System.out.println("test1 B");
}
}

public class outputtest{
 public static void main(String[] args){
 A b = new B();
 b.test1();

}
}

What is the output?

1.test1 A
2.test1 B
3.Not complile because test1() method in class A is not visible.
4.None of the above.

Explanation :
C is the correct answer.

Not complile because test1() method in class A is not private so it is not visible.



Question - 37
public class A{
 private void test1(){

          System.out.println("test1 A");
     }
}


public class B extends A{
public void test1(){

     System.out.println("test1 B");
}
}

public class Test{
public static void main(String[] args){
            B b = new B();
            b.test1();
}
}

What is the output?

1.test1 B
2.test1 A
3.Not complile because test1() method in class A is not visible
4.None of the above

Explanation :
A is the correct answer.

This is not related to superclass , B class object calls its own method so it compile and
output normally.



Question - 38
public class A{
 public void test1(){

          System.out.println("test1 A");
     }
}


public class B extends A{
public void test1(){

     System.out.println("test1 B");
}
}

public class Test{
public static void main(String[] args){
A b = new B();
        b.test1();

}
}

What is the output?

1.test1 B
2.test1 A
3.Not complile because test1() method in class A is not visible
4.None of the above

Explanation :
A is the correct answer.

Superclass reference of subclass point to subclass method and superclass variables.
Question - 39
What is the output of the below code ?
class c1
{
public static void main(String a[])
{
c1 ob1=new c1();
Object ob2=ob1;
System.out.println(ob2 instanceof Object);
System.out.println(ob2 instanceof c1);
}
}

1.Prints true,false
2.Print false,true
3.Prints true,true
4.compile time error

Explanation :
C is the correct answer.

instanceof operator checks for instance related to class or not.



Question - 40
public class C {

     public C(){

     }

}

public class D extends C {

     public D(int i){

          System.out.println("tt");
     }

     public D(int i, int j){

          System.out.println("tt");
     }

}

Is C c = new D(); works ?

1.It compile without any error
2.It compile with error
3.Can't say
4.None of the above

Explanation :
B is the correct answer.

C c = new D(); NOT COMPILE because D don't have default constructor. If super
class has different constructor other then default then in the sub class you can't use
default constructor



Question - 41
public class C {

     public C(){

     }

}

public class D extends C {

     public D(int i){

          System.out.println("tt");
     }

     public D(int i, int j){

          System.out.println("tt");
     }

}

Is C c = new D(8); works ?

1.It compile without any error
2.It compile with error
3.Can't say
4.None of the above

Explanation :
A is the correct answer.

C c = new D(8); COMPILE because D don't have default constructor. If super class
has different constructor other then default then in the sub class you can't use default
constructor



Question - 42
public class C {
public C(int i){

     }

}

public class D extends C {

     public D(){

     }

}
is this code compile without error?

1.yes, compile without error.
2.No, compile with error.
3.Runtime Exception
4.None of the above

Explanation :
B is the correct answer.

We need to invoke Explicitly super constructor();



Question - 43
public class SuperClass {
    public int doIt(){
        System.out.println("super doIt()");
        return 1;
    }

}

public class SubClass extends SuperClass{

     public int doIt()
     {
         System.out.println("subclas doIt()");
         return 0;
     }

     public static void main(String... args)
     {
         SuperClass sb = new SubClass();

                sb.doIt();


     }

}
What is the output ?
1.subclas doIt()
2.super doIt()
3.Compile with error
4.None of the above

Explanation :
A is the correct answer.

method are reference to sub class and variables are reference to superclass.



Question - 44
public class SuperClass {
    public int doIt(){
        System.out.println("super doIt()");
        return 1;
    }

}

public class SubClass extends SuperClass{

     public long doIt()
     {
         System.out.println("subclas doIt()");
         return 0;
     }

     public static void main(String... args)
     {
         SuperClass sb = new SubClass();

                sb.doIt();


     }

}
What is the output ?

1.subclas doIt()
2.super doIt()
3.Compile with error
4.None of the above

Explanation :
C is the correct answer.

The return type is incompatible with SuperClass.doIt(). Return type of the method
doIt() should be int.
Question - 45
public class SuperClass {
    private int doIt(){
        System.out.println("super doIt()");
        return 1;
    }

}

public class SubClass extends SuperClass{

     public long doIt()
     {
         System.out.println("subclas doIt()");
         return 0;
     }

     public static void main(String... args)
     {
         SuperClass sb = new SubClass();

                sb.doIt();


     }

}
What is the output ?

1.subclas doIt()
2.super doIt()
3.Compile with error
4.None of the above

Explanation :
C is the correct answer.

The method doIt() from the type SuperClass is not visible.



Question - 46
public class SuperClass {
    public final int doIt(){
        System.out.println("super doIt()");
        return 1;
    }

}

public class SubClass extends SuperClass{

     public long doIt()
{
          System.out.println("subclas doIt()");
          return 0;
     }

     public static void main(String... args)
     {
         SuperClass sb = new SubClass();

                sb.doIt();


     }

}
What is the output ?

1.subclas doIt()
2.super doIt()
3.Compile with error
4.None of the above

Explanation :
C is the correct answer.

Cannot override the final method from SuperClass



Question - 47
What will be the result of compiling the following code:

public class SuperClass {
    public int doIt(String str, Integer... data)throws Exception{
        String signature = "(String, Integer[])";
        System.out.println(str + " " + signature);
        return 1;
    }

}

public class SubClass extends SuperClass{

     public int doIt(String str, Integer... data)
     {
         String signature = "(String, Integer[])";
         System.out.println("Overridden: " + str + " " + signature);
         return 0;
     }

     public static void main(String... args)
     {
         SuperClass sb = new SubClass();
         sb.doIt("hello", 3);
     }

}
1.Overridden: hello (String, Integer[])
2.hello (String, Integer[])
3.Complile time error.
4.None of the above

Explanation :
C is the correct answer.

Unhandled exception type Exception.



Question - 48
What will be the result of compiling the following code:

public class SuperClass {
    public int doIt(String str, Integer... data)throws
ArrayIndexOutOfBoundsException{
        String signature = "(String, Integer[])";
        System.out.println(str + " " + signature);
        return 1;
    }

}


public class SubClass extends SuperClass{

     public int doIt(String str, Integer... data) throws Exception
     {
         String signature = "(String, Integer[])";
         System.out.println("Overridden: " + str + " " + signature);
         return 0;
     }

     public static void main(String... args)
     {
         SuperClass sb = new SubClass();
         try{
              sb.doIt("hello", 3);
         }catch(Exception e){

          }

     }

}

1.Overridden: hello (String, Integer[])
2.hello (String, Integer[])
3.The code throws an Exception at Runtime.
4.Compile with error
Explanation :
D is the correct answer.

Exception Exception is not compatible with throws clause in SuperClass.doIt(String,
Integer[]). The same exception or subclass of that exception is allowed.



Question - 49
public class SuperClass {
    public ArrayList doIt(){
        ArrayList lst = new ArrayList();
        System.out.println("super doIt()");
        return lst;
    }

}

public class SubClass extends SuperClass{

     public List doIt()
     {
         List lst = new ArrayList();
         System.out.println("subclas doIt()");
         return lst;
     }

     public static void main(String... args)
     {
         SuperClass sb = new SubClass();

                sb.doIt();


     }

}

What is the output ?

1.subclas doIt()
2.super doIt()
3.Compile with error
4.None of the above

Explanation :
C is the correct answer.

The return type is incompatible with SuperClass.doIt(). subtype return is eligible in
jdk 1.5 for overidden method but not super type return. super class method return
ArrayList so subclass overriden method should return same or sub type of ArrayList.
Question - 50
public class SuperClass {
    public List doIt(){
        List lst = new ArrayList();
        System.out.println("super doIt()");
        return lst;
    }

}
public class SubClass extends SuperClass{

     public ArrayList doIt()
     {
         ArrayList lst = new ArrayList();
         System.out.println("subclas doIt()");
         return lst;
     }

     public static void main(String... args)
     {
         SuperClass sb = new SubClass();

                sb.doIt();


     }

}


What is the output ?

1.subclas doIt()
2.super doIt()
3.Compile with error
4.None of the above

Explanation :
A is the correct answer.

subtype return is eligible in jdk 1.5 for overidden method but not super type return.
super class method return List so subclass overriden method should return same or
sub type of List.



Question - 51
class C{
int i;
public static void main (String[] args) {
    int i;                      //1
    private int a = 1;          //2
    protected int b = 1;        //3
public int c = 1;                   //4
     System.out.println(a+b+c);          //5
}}

1.compiletime error at lines 1,2,3,4,5
2.compiletime error at lines 2,3,4,5
3.compiletime error at lines 2,3,4
4.prints 3

Explanation :
B is the correct answer.

The access modifiers public, protected and private, can not be applied to variables
declared inside methods.



Question - 52
Which variables can an inner class access from the class which
encapsulates it.

1.All final variables
2.All instance variables
3.Only final instance variables
4.All of the above

Explanation :
D is the correct answer.

Inner classes have access to all variables declared within the encapsulating class.



Question - 53
class c1
{
     public void m1()
       {
           System.out.println("m1 method in C1 class");
         }
}
class c2
{
    public c1 m1()
     {
         return new c1(){
           public void m1()
              {
                  System.out.println("m1 mehod in anonymous class");
       }};}
public static void main(String a[])
  {
c1 ob1 =new c2().m1();
        ob1.m1();
}}

1.prints m1 method in C1 class
2.prints m1 method in anonumous class
3.compile time error
4.Runtime error

Explanation :
B is the correct answer.

the anonymous class overrides the m1 method in c1.so according to the dynamic
dispatch the m1 method in the anonymous is called



Question - 54
abstract class vehicle{
abstract public void speed();
}
class car extends vehicle{
public static void main (String args[]) {
vehicle ob1;
ob1=new car();   //1


}}

1.compiletime error at line 1
2.forces the class car to be declared as abstract
3.Runtime Exception
4.None of the above

Explanation :
B is the correct answer.

Abstract method should be overriden otherwise Subclass should be abstract.



Question - 55
abstract class C1{
public void m1(){                //1
}}
abstract class C2{
 public void m2(){              //2
}}

1.compile time error at line1
2.compile time error at line2
3.The code compiles fine
4.None of the above

Explanation :
C is the correct answer.

since the class C2 is abstract it can contain abstract methods



Question - 56
class base
{
base(int c)
{
  System.out.println("base");
}
}
class Super extends base
{
  Super()
  {
      System.out.println("super");
    }
public static void main(String [] a)
{
        base b1=new Super();

}
}

1.compile time error
2.runtime exceptione
3.the code compiles and runs fine
4.None of the above

Explanation :
A is the correct answer.

If super class has different constructor other then default then in the sub class you
can't use default constructor.



Question - 57
class C1{
public void m1(){    // 1
}
}
class C2 extends C1{ //2
private void m1(){
}
}
1.compile time error at line1
2.compile time error at line2
3.Runtime exception
4.None of the above

Explanation :
B is the correct answer.

extending to assign weaker access not allowed. Overridden method should be more
public.



Question - 58
class C1
{
static interface I
{
  static class C2
  {
    }

}
public static void main(String a[])
{
C1.I.C2 ob1=new C1.I.C2();
System.out.println("object created");
}
}

1.prints object created
2.Compile time error
3.Runtime Excepion
4.None of the above

Explanation :
A is the correct answer.

A static interface or class can contain static members.Static members can be accessed
without instantiating the particular class



Question - 59
class C1
{
  static class C2
   {
        static int i1;
     }
public static void main(String a[])
{
     System.out.println(C1.C2.i1);
}
}

1.prints 0
2.Compile time error
3.Runtime exception
4.None of the above

Explanation :
A is the correct answer.

static members can be accessed without instantiating the particular class



Question - 60
What will happen when you attempt to compile and run the following
code

class Base{
protected int i = 99;
}
public class Ab{
private int i=1;
public static void main(String argv[]){
Ab a = new Ab();
a.hallow();
}

        abstract void hallow(){
         System.out.println("Claines "+i);
         }

}

1.Compile time error
2.Compilation and output of Claines 99
3.Compilation and output of Claines 1
4.Compilation and not output at runtime

Explanation :
A is the correct answer.

Abstract and native methods can't have a body: void hallow() abstract void hallow()



Question - 61
public class A extends Integer{
public static void main(Sring[] args){
System.out.println("Hello");
}
}
What is the output?

1.Hello
2.Compile Error
3.Runtime
4.None of the above

Explanation :
B is the correct answer.

final class can't be extended. Integer is final class.



Question - 62
which statement is correct ?

1.A nested class is any class whose declaration occurs within the body of another
class or interface
2.A top level class is a class that is not a nested class.
3.A top level class can be private
4.none of the above

Explanation :
A and B is the correct answer.

A nested class is any class whose declaration occurs within the body of another class
or interface A top level class is a class that is not a nested class.



Question - 63
Constructor declarations can be include the access modifiers?

1.public
2.protected
3.private
4.All of the above

Explanation :
D is the correct answer.

constructor declarations may include the access modifiers public, protected, or private



Question - 64
private class B {

     public static void main(String[] args){
         System.out.println("DD");
         B b = new B();
     }

}

What is the output ?

1.DD
2.Compile Error.
3.Runtime Exception
4.None of the above.

Explanation :
B is the correct answer.

Only public, abstract and final is permitted for class modifier.



Question - 65
public class Point {
    int x = 1, y = 1;
    abstract void alert();
}

Is the code compile without error ?

1.compile without error
2.compile with error , because class should be abstract.
3.Can't say
4.None of the above.

Explanation :
B is the correct answer.

If there is any abstract method in a class then the class should be abstract.



Question - 66
abstract class Point {
    int x = 1, y = 1;
    abstract void alert();
}

public class A{
public static void main(String[] args){
Point p = new Point();
}
}
What is the output ?

1.compile without error
2.compile with error.
3.Can't say
4.None of the above.

Explanation :
B is the correct answer.

abstract class can't be instantiated.
Modeling Web Business Processes with OO-H
               and UWE1
                           NORA KOCH AND ANDREAS KRAUS
                          Ludwig-Maximilians-Universität München.
                                         Germany

              CRISTINA CACHERO AND SANTIAGO MELIÀ
                      Universidad de Alicante, Spain
________________________________________________________________________
Business processes, regarded as heavy-weighted flows of control consisting of activities and transitions, pay an
increasingly important role in Web applications. In order to address these business processes, Web
methodologies are evolving to support its definition and integration with the Web specific aspects of content,
navigation and presentation.
This paper presents the model support provided for this kind of processes by both OO-H and UWE. For this
support both approaches use UML use cases and activity diagrams and provide appropriate modeling extensions.
Additionally, the connection mechanisms between the navigation and the process specific modeling elements
are discussed. As a representative example to illustrate our approach we present the requirements, analysis and
design models for the amazon.com Website with focus on the checkout process. Our approach includes
requirements and analysis models shared by OO-H and UWE and provides the basis on which each method
applies its particular design notation.
Categories and Subject Descriptors: H.5.4 [Information Interfaces and Presentation]:
Hypertext/Hypermedia – Architecture; Navigation; User Issues; D.2.2 [Software Engineering]: Design Tools
and Techniques – Object-oriented Design Methods; D.2.1 [Software Engineering]: Requirements Specification
– Methodologies; I.6.5 [Computing Methodologies]: Simulation and Modeling – Model Development
General Terms: Design, Experimentation, Human Factors
Additional Key Words and Phrases: Web Engineering, UML, Visual Modeling, Process Modeling, UML
Profile
________________________________________________________________________

1. INTRODUCTION
Business processes, regarded as heavy-weighted flows of control consisting of activities
and transitions [UML 2003], have always paid an important role in software development
methods, to the point that many process proposals include the definition of an explicit
view (the process view) in order to address their complexity. However, such processes
have been only tangentially tackled in most existing Web Application modeling
approaches [Retschitzegger & Schwinger 2000]. This reality is partly due to the fact that
most of these methods were born with the aim of successfully modeling Information
Systems (IS) [Baresi et al. 2001, Schwabe et al. 2001, Ceri et al. 2002, De Troyer &
Casteleyn 2001, Gomez et al. 2001, Koch & Kraus, 2002], which ‘store, retrieve,

1
  This work has been partially supported by the European Union within the IST project AGILE – Architectures
for Mobility (IST-2001-32747), the German BMBF-project GLOWA-Danube, and the Spain Ministry of
Science and Technology, project number TIC2001-3530-C02-02.
Authors' addresses: Nora Koch and Andreas Kraus, Ludwig-Maximilians-Universität München, Germany,
http://www.pst.informatik.uni-muenchen.de, {kochn,krausa}@informatik.uni-muenchen.de. Cristina Cachero
and Santiago Meliá, Universidad de Alicante, España, http://www.ua.es, {ccachero,santi}@dlsi.ua.es.
transform and present information to users. [They] Handle large amounts of data with
complex relationships, which are stored in relational or object databases’ [Korthaus
1998]. Therefore, Web modeling approaches have intensively worked on (1) the
definition of suitable constructs to address the user navigation through the domain
information space and (2) the inclusion of mechanisms to model the change in such
information space through the invocation of synchronous retrieval and update operations.
In contrast, requirements posed on modern Web applications imply to regard them not
only as Information Systems but also as Business Systems, that is, applications centered
on goals, resources, rules and, mainly, the actual work in the business (business
processes). Workflow management systems, which have proven successful for the
definition and control of these processes, fall short however when faced to the problem of
defining rich business-enabled Web interfaces that, aware of the underlying workflow,
support and guide the user through it, preserving at the same time the hypertext
flexibility.
The hypermedia community, conscious of this gap, has been working for some time on
the extension of Web modeling methods (which are specially suited to deal with the
complexity of Web interfaces) with new mechanisms that permit the definition and
integration of lightweight business processes with the rest of the views. This extension
may be done following at least two different approaches: on one hand, traditional content,
navigation and/or presentation models may be enriched to capture this workflow.
Examples in this sense include Araneus2 [Atzeni & Parente 2001], which defines the
mechanisms to allow the grouping of activities into phases, Wisdom [Nunes & Cunha
2000], which proposes a UML extension that includes the use of a set of stereotyped
classes, or WebML [Brambilla et al. 2002] which enriches the data and the hypertext
models to define lightweight web-enabled workflows. On the other hand, additional
models may be defined, and its connection with the pre-existing content, hypertext and/or
presentation views established. This has been the approach jointly followed by UWE and
OO-H, as we will present in this paper.
Our aim in this paper has been therefore to find a common set of modeling concepts that
suffices to define sound, non-trivial business processes and that could be equally useful in
other existing methodologies. In order to define the necessary constructs and modeling
activities, we have decided to adhere to well known object-oriented standards, namely to
the semantics and notation provided by UML. Using UML to model business processes is
not new; authors like [Nunes & Cunha 2000, Markopoulos 2000] have already
acknowledged its feasibility and excellence. From the set of modeling techniques
provided by the UML, the activity diagram is the most suitable mechanism to model the
business workflow, and so has been adopted by both OO-H and UWE to define the
different processes. In this diagram, activity states represent the process steps, and
transitions capture the process flow, including forks and joins to express sets of activities
that can be processed in arbitrary order.
In order to reach our goal, this work is organized as follows: Sections 2 and 3 present the
analysis steps, equal for both methodologies. Section 4 and Section 5 describe the design
steps for OO-H and UWE, respectively. Last, Section 6 outlines conclusions while
Section 7 proposes future lines of research. In order to better illustrate the whole
approach, a simplified view of the well-known Amazon checkout process
(http://www.amazon.com) is going to be employed all along the paper.
2. THE ROLE OF BUSINESS PROCESSES IN REQUIREMENT
   ANALYSIS
The inclusion of a business process in any Web modeling approach affects every stage of
development, from requirements analysis to implementation. Regarding requirements
analysis, whose goal is the elicitation, specification and validation of the user and
customer needs, this activity includes the detection of both functional and non-functional
requirements, both of which may get affected by process concerns.
Although there is a lack of a standardized process supporting requirements analysis, best
practices in the development of general software applications provide a set of techniques.
A recent comparative study [Escalona & Koch 2003] about requirements engineering
techniques for the development of Web applications showed that use case modeling is the
most popular technique proposed for the specification of requirements while interviewing
is the most used technique for the capture of those requirements. These results are not
surprising; traditional software development requires interviewing as an intuitive and
widely used procedure to guide a “conversation with a purpose” [Kahn & Cannell 1957],
and use cases are a well known approach for graphical representation and description of
requirements suggested by [Jacobson et al. 1992]. Use case modeling is a powerful
formalism to express functional requirements of business intensive – Web or non-Web –
applications.
In this sense, OO-H and UWE are object-oriented approaches (partially and completely
based on UML, respectively) and both of them include the use case modeling technique
to gather the requirements of Web applications. To define a use case model the first step
is to identify actors and the corresponding use cases of the application. Such a use case
model usually includes a use case diagram which is usually enough to describe the
functionality of simple systems, such as of Web information systems. On the other hand,
Web applications including business processes require a more detailed description of
these – more complex – sequences of actions. In order to address this additional
complexity as it is shown in the next section, both approaches propose the use of UML
activity diagrams.
In our running example we have identified two actors that play a relevant role in the
checkout process: the NonRegisteredUser and the Customer. The non-registered user can
– among other activities – search and select products, add products to the shopping cart
and login into the Amazon Web application. The Customer inherits from the
NonRegisteredUser and is allowed among other things (after logged-in) to start the
checkout process.
Fig. 1 presents a partial view of the use case diagram corresponding to the Amazon Web
application. For the sake of simplicity, in this diagram we have centered on the use cases
that are directly related to the selection of items and the checkout process, therefore
ignoring others such as, just to name a few, AddToWishList, CheckOrder or ReturnItems,
which are however also relevant tasks from the user point of view.
In this diagram we can observe how a NonRegisteredUser may select product items. Such
selection may be performed using a system search capability, which is modeled by means
of an inheritance relationship between the use cases SelectProductItems and
SearchProductItems. Also, this user may decide to add any selected product to his
shopping cart. This fact is modeled by means of an «extend» dependency between the use
case AddToShoppingCart and the SelectProductItems use case.
                                                           <<extend>>


                                    <<navigation>>                      AddToShoppingCart
                                   SelectProductItems




               <<navigation>>                                               <<navigation>>
                                                   NonRegisteredUser
             SearchProductItems                                               ViewCart




                          SignIn

                       <<extend>>                       Customer


                                                         <<include>>
                                   Checkout                                    SendInvoice

Fig. 1. Use Case Diagram of the Checkout Process in www.amazon.com

At any time, the user may decide to ViewCart, in order to check the items included so far
in his shopping basket. Also, he could decide to personalize her view, for what he would
have to SignIn. Furthermore, only a signed-in user may proceed to checkout. This
situation is again modeled by means of an «extend» dependency between the use cases
SigIn and Checkout. The completion of the checkout process implies the sending of a
notification with the invoice associated with the purchase. We have modeled this action
as a use case that is related («include» dependency) to the Checkout use case. The
Customer may also wish to be sent an additional invoice at any time after the purchase; in
Fig. 1 this fact is captured by means of an association between the actor Customer and
the SendInvoice use case.
If we now analyze the inner flow of control of each defined use case in the context of the
Amazon Web application, we may note how some flows are trivial from the business
point of view, as they only express navigation activities. For this kind of use cases, we
propose the use of a «navigation» stereotype, as defined in [Baresi et al. 2001]. Others,
on the contrary, imply a complex flow of control, and require further refinements, as we
will show next.

3. ANALYSIS PHASE IN PROCESS-AWARE WEB APPLICA-
   TIONS
Once the requirements have been clearly stated, both in OO-H and UWE the next step
consists on the analysis of the problem domain. This analysis phase has traditionally
involved in both methods the definition of a conceptual model reflecting the domain
structure of the problem. This model however does not provide the mechanisms to
specify process concerns. That is the reason why we have included a new model, the
process model that enriches this analysis phase. Next we will show how these models can
be applied to our running example.

3.1. CONCEPTUAL MODEL
The definition of a conceptual model by means of a UML class diagram is a common
feature in most Web modeling approaches, including UWE and OO-H. Back to our
example, we have defined a common conceptual model, materialized in a UML class
diagram that is depicted in Fig. 2.

                       ConceptualModel                                       UserModel

                                                             ShoppingCart                    Customer
                                                                                            name
                                                             add()                          creditCard
                                                                              1..*   0..1
                                                             checkout()
              Book                                                   1
                                                                     *
                          Product                             ShoppingCart
              DVD        name                                     Item
                         price    1                           quantity
                                                         *
                                                                                                 *
               CD          *
                                                                                           Address
                                         OrderItem                       +deliveryAddress street
                                         quantity                                         zip-code
                                                     1                               0..1 country

                          *
                                                                                                  1
                          Order                                              +invoiceAddress
                       orderID       1
                       invoiceNumber

                       sendInvoice()



Fig. 2. Conceptual Model of the Checkout Process in www.amazon.com

This class diagram is made up of two packages: the User Model and the Conceptual
Model. The first one includes the structures directly related to the individual user, such as
the ShoppingCart or the different Addresses provided by each Customer. The Conceptual
Model on the other hand maintains information related to domain objects such as
Products and Orders. Note how this diagram is a simplification of the actual Amazon
domain model, and reflects only a possible subset of constructs that are needed to support
the checkout process. In this diagram we can observe how a customer (which may be
anonymous before logging-in in the system) has a ShoppingCart, which is made-up of
ShoppingCartItems (each one associated with a Product, which may be a Book, a DVD or
a CD, just to name a few). On the other hand each customer has a set of predefined
Addresses that, once the order has been created, are used both to send the different items
and to set the invoice address. When the customer decides to checkout, the system creates
a new Order and converts the ShoppingCartItems into OrderItems. When the order is
finally placed, an invoiceNumber is associated to the order.
The conceptual model is not well suited to provide information on the underlying
business processes that drive the user actions through the application. For this reason,
OO-H and UWE have included a process model that is outlined in the next two sections.
3.2. PROCESS MODEL
Process modeling (also called task modeling) stems from the Human Computer
Interaction (HCI) field. Different UML notations have already been proposed for process
modeling. Wisdom [Nunes & Cunha 2000] is a UML extension that proposes the use of a
set of stereotyped classes that make the notation not very intuitive. Markopoulus
[Markopoulos 2000] instead makes two different proposals: an UML extension of use
cases and another one based on statecharts and activity diagrams. Following this last
trend, we have opted to use activity diagrams, due to their frequency of use and their
flexibility to model flows.
An activity diagram is a special case of a state diagram in which all (or at least most) of
the states are actions or subactivity states and in which all (or at least most) of the
transitions are triggered by completion of the actions or completion of the subactivities in
the source states. The entire activity diagram is attached (through the model) to a UML
classifier, such as a use case, or to a package, or to the implementation of an operation
[UML 2003]. The UML modeling elements for a process model are activities, transitions
and branches. Activities represent atomic actions of the process and they are connected
with each other by transitions (represented by solid arrows) and branches (represented by
diamond icons). The branch conditions govern the flow of control and in the analysis
process model they can be expressed in natural language.
As stated before, both OO-H and UWE use activity diagrams to complement the domain
model and define the inner flow of control of non trivial use cases. In Fig. 3 an activity
diagram representing the simplified flow of control of the Amazon Checkout process
(depicted as a non-navigational use case in Fig. 1) is presented.


                  [ error ]                  SignIn


                                                      [ newCustomer ]


                          [ returningCustomer ]                                                    [ error ]
                                                                     AddNewCustomer


             [ change ]                   SetOptions

                                                                                          newCustomer :
                                                                                            Customer
                                                           [ newCustomer ]

                          [ returningCustomer ]
                                                                        SetPassword

                                          PlaceOrder
                                exit/ delete Items of ShoppingCart



                                                                                newOrder : Order
                                          SendInvoice




Fig. 3. Process Model of the Checkout Process in www.amazon.com
In this diagram we can observe how a SignIn subactivity starts the process. Next,
depending on whether the user is new in the system or not, he can be added to the system
or directly driven to the SetOptions subactivity state that permits the user to establish
every purchase option (see ). Once this activities has been completed, the user may set his
password (only if he is a new customer), place the order and be sent an invoice with the
purchase details.
Subactivity states, as shown in the diagram of Fig. 3, express the hierarchical
decomposition of a process. A subactivity state invokes another activity diagram. When a
subactivity state is entered, the nested activity graph is executed. A single activity graph
may be invoked by many subactivity states meaning that activity diagrams can be (re-
)used within the context of different processes and sub processes (i.e. subactivities). In
our example, Fig. 4 shows the flow of control of the SetOptions subactivity state
represented by a UML activity diagram. This diagram includes activities for the user to
enter shipping and payment options, wrapping options and confirm the cart items before
placing the order. In the checkout process only options not already set before e.g. in
previous checkouts or those that the user explicitly wants to change are triggered in the
process context.




            [ not set or change ]   [ not set or change ]   [ not set or change ]     [ not set or change ]


               ConfirmItems           SetWrapOptions        SetShippingOptions      SetPaymentOptions




Fig. 4. Activity Diagram of the SetOptions Process in www.amazon.com

In Fig. 3 we can also observe how the use and extend dependencies defined in the use
case diagram of Fig. 1 influence the flow of control of the process, and are materialized
in the inclusion of complementary activities (see e.g. SendInvoice) and subactivity states
(e.g. SignIn) that, as suggested by such dependencies, play a role in the definition of the
checkout process.
Finally, the activity diagram associated with a given Web-aware business process can
also be enriched with object flows indicating objects that are relevant at analysis level as
input and output to crucial activities. In the example a new Customer is created as result
of the AddNewCustomer activity and a new Order object is created as result of the
PlaceOrder activity.
Once this analysis model has been defined, at least two approaches can be followed:
    •    The definition of a navigation model that is driven by a (refined) process flow
         model. This tight integration between process and navigation expresses the
interplay between the user interface design and the steps inferred from the
         process definition.
    •    The definition of a navigation model that is enriched to reflect a set of
         integration points, that is, points in which the user may leave the navigation
         view to enter a process design view.
Next, we will show how OO-H and UWE, each implements one of these approaches, and
how in spite of this fact, analysis models are still fully reusable and a common ground for
discussion.

4. DESIGN OF WEB BUSINESS PROCESS WITH OO-H
OO-H [Cachero 2003; Gomez et al. 2001] is a generic approach, partially based on the
Object Oriented paradigm, that provides the designer with the semantics and notation
necessary for the development of personalized Web-based interfaces. Like many other
approaches, the OO-H modeling process is driven by the set of identified user
requirements, and explicitly supports the definition of different user interfaces depending
on the actor that is accessing the application. The whole method is supported by the Case
tool VisualWADE, a modeling environment that includes a set of model compilers to
provide automatic code generation capabilities.
From the six complementary views included in OO-H (requirement, conceptual, process,
navigation, presentation and architectural), in this article we will center on the process
view. This process view is based, as stated above, on a set of activity diagrams that
supplement the information contained in the domain model. In order to make this
connection between both models explicit, both class and activity diagrams are refined
during the design phase, and the correspondence between the process constructs and the
domain constructs is set. On this refined process view, a set of mapping rules can be
applied in order to get a default navigation view and assure the traceability between both
models, as will be explained in section 4.2.

4.1. PROCESS MODEL REFINEMENT
OO-H bases the process refinement on the concept of service, regarded as an interface
whose purpose is collect a set of operations that constitute a coherent service offered by
classifiers, and so provide a way to partition and characterize groups of operations
[UML 2003].
Services in OO-H can be classified according to several orthogonal characteristics,
among which we outstand (1) synchronicity, (2) activating agent, (3) granularity (number
of operations supporting the service) and (4) transactionality [Cachero 2003]. OO-H
centers on synchronous, user-activated services. Inside this group, OO-H is well suited to
provide an arbitrary complex interface to single (either transactional or not) services,
where by single we mean services supported by exactly one underlying class operation.
That is the case of Create, Delete and Update operations, which are at the core of typical
single, transactional (ACID) services.
On the other hand, the definition of an interface for a compound service, which involves
more than one domain operation, presents special challenges from the user interface
modeling point of view. In this kind of services, the user interface is responsible for
guiding the user through the different domain operations following a predefined flow of
control, which may involve both activity and information dependencies. A checkout
service such as the one included in Amazon is, from the OO-H point of view, a
compound, non-transactional service. For this service, a possible activity diagram
representing the system flow of control has been already presented in Fig. 3.
In order to further refine the analysis process view, we must take into account detailed
class properties. A new class diagram with a more exhaustive list of attributes and
methods is shown in Fig. 5. Note how this diagram can be regarded as a possible
evolution of the one presented in Fig. 2.
                                                                                                           Customer
                                                                           ShoppingCart
                                                                                                           cName
                                                                             ID                            emailAddress
    Book              CD                   DVD                                                             passwd
                                                                             addItem()       1..*   0..1
                                                                             checkout()                    login()
                                                                             deleteItems()                 new()
                                                                                                           setPasswd()
                                                                                  1..1

                                                                                  *
                   Product
                                                                         ShoppingCartItem
                  pName
                                 1..1                                *     quantity
                  price


                       +
                                                                                                                *
                                                                                                            Address
                                                 OrderItem
                                                 quantity                                                  street
                                                                 *                                  1..1   zip-code
                                                 confirmItem()                                             country


                                                                                                                1..1
                       +
                    Order
               orderID
               invoiceNumber
               shippingSpeed

               new()
               setShippingAddress() 1..1
               setBillingAddress()
               setPaymentOptions()
               placeOrder()
               setWrappingOptions()
               sendInvoice()



Fig. 5. OO-H Refined Class Diagram of the Checkout Process in www.amazon.com

Taking into account the underlying operations, it is possible to construct a more detailed
activity diagram, such as the one presented in Fig. 6. In this figure we observe several
examples of refinements allowed in OO-H at this level of abstraction:
•    Some subactivity states may be redefined as call states, implying that a single
     operation (at most) gives them support. That is the case of the SignIn subactivity
     state (see Fig. 3) that has been now redefined as a call state.
•    Some call states may be merged under a common subactivity state. This feature is
     specially useful when a transaction is detected which involves several call states. In
     our example, we have considered that PlaceOrder and SendInvoice are related
     activities (in the checkout process the invoice is automatically sent after the order
     has been placed), and that an error while sending the invoice implies that the order
     cannot be placed, because the user would lack the necessary notification. Therefore
     we have defined a transactional subactivity state that includes both call states (see
     Fig. 6).
•    Call states may be complemented (if necessary) with information regarding the
     domain operation that gives them support in a do section. For example, the
     transactional activity SetPasswd() states in the refined activity diagram that this
     activity is supported by the operation setPasswd(in passwd:String), which belongs
     to the Customer class. Note how this fact could also have been modelled by means
     of swimlanes added to the diagram.
•    A new «transactional» stereotype must be applied to the different activities. This
     stereotype reflects the transactional character of both call states and subactivity
     states. A transactional activity/subactivity state presents the classical ACID
     properties. Furthermore, transactional subactivity states imply that every underlying
     activity or subactivity state belongs to the same transaction. On the contrary, a non-
     transactional subactivity state does not pose any requirement over the elements
     included. Back to our example, the SignIn activity has been defined as non-
     transactional. In our approach this fact implies that the activity does not need logic
     support, as it might be modelled with the aid of filters and navigation constructs, as
     we will show in section 4.2


                                <<nonTransactional>>
         [ Error ]                     SignIn

                               do/ Customer.login()


                                                                           <<transactional>>
                                                     [ newCustomer ]       AddNewCustomer
                                                                                                        [ Error ]
                                                                       do/ Customer.new(eMail)
                     [ returningCustomer ]

                                <<nonTransactional>>
                                     SetOptions

                                entry/ Order.new()

                                                                                <<transactional>>
                                                 [ newCustomer ]                   SetPasswd

                                                                       do/ Customer.setPasswd(passwd)
                     [ returningCustomer ]

                                  <<transactional>>
                                     PlaceOrder

                        exit/ ShoppingCart.deleteItems()




Fig. 6. OO-H Refined Activity Diagram of the Checkout Process in
www.amazon.com

For the sake of simplicity, in Fig. 6 we have hidden other possible refinements, such as
for example the set of OCL guard conditions that may be associated with the transitions,
the OCL formulae that may be associated to non-transactional activities or the detailed
flow of objects among activities and/or subactivity states, which would also be relevant at
this stage of the model and from which it would be possible to infer certain parameter
dependencies during the invocation of the underlying methods if necessary.
4.2. DEFAULT NAVIGATION MODEL
As we have stated before, OO-H redefines call states so that they can be mapped to
underlying domain constructs. In order to support this mapping, the UML metamodel
must be conservatively extended to capture this connection between OO-H activities (a
specialization of the UML activity construct) and conceptual operations and/or classes.
The reason for this connection is that, as we will see next, in this way it is possible to
automatically generate a default navigation view that not only speeds up the development
cycle but also assures the interface guidance and support to this process.
The navigation model in OO-H is defined by means of a Navigation Access Diagram
(NAD). This diagram is made up of collections (depicted as an inverted triangle and
which capture in OO-H the menu concept), navigation targets (navigation subsystems
depicted with a package symbol), navigation classes (views on conceptual classes,
depicted with the class symbol) and navigation links (which describe the paths the user
may follow through the system and that are depicted with the arrow symbol).
Navigational links, being a central construct in OO-H and the core of the navigation
view, have several relevant characteristics associated:
•   Type. It can be set to (1) requirement link, which determines the beginning of the
    user navigation through the diagram, (2) traversal link, which defines navigation
    paths between information structures or (3) service link, which provides an
    arbitrarily complex user interface to assign values to the underlying in operation
    parameters and/or define the visualization of the operation results (out parameters).
•   Activating Agent: can be set to user (depicted as a solid arrow) or system (depicted
    as a dotted arrow)
•   Navigation effect: can be set to origin (depicted as a hollow arrow end) or
    destination (filled arrow end).
Filters, defined as expressions loosely based on OCL and which are associated to links. In
these expressions, a question mark (?) symbol represents user input.
All these symbols can be observed in Fig. 7. This figure depicts a possible OO-H
navigation model corresponding to our checkout running example. Fig. 7 also illustrates
how the process view provides the necessary information to generate a default navigation
view, enabling in this way the automatic generation of a navigation model out of a
process model. In order to get this navigation model, we have applied a predefined set of
mapping rules, which can be summarized as follows:
In Table 1 we observe how non-transactional activities are transformed into navigational
links, which will need to be further refined with a navigation filter that completes the
activity specification. Transactional activities and/or transactional subactivity states on
the contrary require the support of an underlying domain operation that hides and
preserves such transactional character. Operations are accessed at NAD level by means of
service links. On the other hand, non-transactional subactivity states can be regarded as
navigational subsystems, and therefore materialized in a OO-H Navigation target
associated with each of the defined subsystems. Transitions trivially map to traversal
links, which are by default activated by the user and cause a change of user view.
Activity Diagram Element                    NAD diagram element

       Non-Transactional Activity                  Navigational link refined with precondition filter

       Transactional Activity                      Service link associated with a Navigational class
       Transition                                  Navigation target
       Subactivity                                 Service link associated with a Navigational class

       Branch                                      Traversal link
       Merge                                       Collection from which a set of Traversal links with
                                                   exclusive filters departs.
       Split-Join                                  Collection at which a set of Traversal links with no
                                                   filters arrives.


Table 1. Mapping Rules between Process View and Navigation View in OO-H

Branches can be regarded as menus where only one option is available at a time. This fact
is modeled in OO-H by means of a collection construct and a set of traversal links, each
one with an exclusive filter associated. Merge constructs, on the other hand, cause the
generation of a collection that is the target for a set of automatic traversal links.
Last, the synchronization bars (split-join constructs) cause the generation of a default
path that traverses the concurrent activities in arbitrary order (namely from top to bottom
and from left to right).

      SignIn[precond:Context.emailAdress=? and Context.password = ?


                          COL1



                                     AddNewCustomer[precond: context.emailAddress=?]
                                                                                           CustomerView: Customer

                                                                                           new()

                         SetOptions
                            DN3




                          COL3


                                      [precond: Context.passwd->isEmpty()]
                                                                             CustomerView2: Customer

                Precond:Context.password->notEmpty()]
                                                                             setPasswd()




                        PlaceOrder
                             DN6




Fig. 7. NAD Diagram for Customer Identification in the Checkout Process

As an illustrating example, and looking back at the activity diagram of Fig. 6, we observe
that the first constructor that appears is the SignIn non-transactional call state. This
activity is materialized in Fig. 7 in a navigational link with an associate filter (OCL
formula) that implements a query over the underlying information repository. After this
query has been performed, and depending on whether the user is new or a returning
customer, a collection construct (col1, see Fig. 7) drives us either to a new() method or to
a SetOptions navigation target respectively. Assuming that the user states he is new, he
will follow the AddNewCustomer link, which first of all will demand the user to enter an
emailAddress that is gathered in an OO-H predefined context object. While the customer
navigational class and the associated service link have been generated automatically, the
filter is a refinement added by the designer on the default model to correctly capture the
Amazon interface.
This email value will be then used to provide a value to one of the parameters defined for
the new() service that can be accessed through the CustomerView. When the underlying
operation returns the control, and assuming that everything is OK, a system automatic
traversal link (dotted arrow) drives the user to the SetOptions Navigation Target.
This diagram also shows the association between activities and classes and/or domain
operations. As an example, the association of the AddNewCustomer activity of Fig. 6
with the new() operation in the Customer class has caused the inclusion of a
CustomerView and a service link associated (see Fig. 7).
If we now enter the SetOptions navigation target, generated after the homonim
subactivity state, we may observe how all options may be performed in parallel.
Navigationally speaking, and in order to assure that the completion of all the parallel
activities is possible, OO-H infers a navigation path that sequentially traverses the
constructs associated with each one of these activities (see Fig. 8).
       OrderItem: OrderItem            Order1: Order               Order2: Order          Order3: Order

       confirmItem()                 setWrappingOptions()        setShippingAddress()   setPaymentOptions()




                COL3          COL4                     COL5             COL6
       LR9




                                            PlaceOrder:: Order


Fig. 8. NAD Diagram Corresponding to the SetOptions Subactivity State

Once the whole navigation model has been refined, a default presentation model can be
automatically generated in the OO-H development environment. In order to complete the
application specification, OO-H provides a presentation model that is partly-based on the
design models presented so far and that falls out of the scope of this paper.
5. DESIGN OF WEB BUSINESS PROCESS WITH UWE
The UWE methodology [Koch & Kraus 2002] is an object-oriented and iterative
approach based on the standard UML. The main focus of UWE is the systematic design
followed by a semi-automatic generation of Web applications. To support the systematic
design the CASE-tool ArgoUWE (an extension of ArgoUML2) is currently being
implemented. The semi-automatic generation of Web applications is supported by the
UWEXML – a model-driven Code Generator for deployment to an XML publishing
framework. Both are part of the OpenUWE development environment. The common
language for data interchange within this architecture is defined by the UWE metamodel
defined as a conservative extension of the UML metamodel and therefore a MOF (Meta
Objects Facility) compatible metamodel [Koch & Kraus 2003].
The UWE metamodel elements are also the basis for the UWE notation which is defined
as a “lightweight” UML profile, i.e. a UML extension based on the extension
mechanisms defined by UML. The UWE profile includes a set of Web specific modeling
elements for navigation, presentation, process and personalization. In this section we will
focus on the notation used by UWE for business processes and the development steps to
build such category of applications.
The UWE design approach for Web business process, in the same way as OO-H does, is
based on the models built during the analysis phase, i.e. the conceptual model and the
process model, both presented in Section 4. It uses standards not only to build the
analysis models, but UWE also sticks to the UML in this design phase. In this phase
UWE selects the appropriate diagram types and proposes to enrich the UWE Profile with
a couple of modeling elements, improving in this way the expressiveness of the UML
constructs for the Web domain. In the treatment of business processes UWE differs from
OO-H by not mapping the process model to the navigation model but additionally
introducing specific process classes that are part of a separate process model with a clear
interface to the navigation model.
Design of Web business applications following the UWE methodology requires the
following activities: First, the refinement of the conceptual model adding attributes and
methods to the already identified classes. We will neither detail this refinement process
nor depict the resulting diagram in this work, as these are well known activities done in
object-oriented development. Second, the integration of the processes in the navigation
model to indicate browsing possibilities. Third, the refinement of the process model
building a process structure and a process flow view. Last but not least, the presentation
model is built based on the navigation and process models showing how the navigation
paradigm and the business processes are combined.

5.1. INTEGRATION OF PROCESSES IN THE NAVIGATION
MODEL
Navigation modeling activities in UWE comprise the construction of the navigation
model in two steps. First, the objective is to specify which objects can be visited by
navigation through the application. Incorporating to this diagram additional constructs it

2
    www.tigris.org
is shown how the user can reach the navigation elements. The navigation model is
represented by a stereotyped class diagram. It includes the classes of those objects which
can be visited by navigation through the Web application, such as classes Product,
ShoppingCart, Order, Customer, Book, etc. UWE provides a set of guidelines and semi-
automatic mechanisms for modeling the navigation of an application, which are detailed
in previous works [Koch and Kraus 2002]. This automation as well as model checking is
supported by the CASE tool ArgoUWE [Zhang 2002].
UWE defines a set of modeling elements used in the construction of the navigation
model. For the first step the «navigation class» and the «navigation link» have been used
until now to model nodes and links. For modeling process-aware Web applications we
introduce two additional stereotypes «process class» and «process link», which are
defined with the following semantic:
•   process class models a class whose instances are used by the user during execution
    of a process. It is possible to define a mapping function between «process class»
    classes and use cases (those use cases not stereotyped as «navigation») in a similar
    way to the mapping function defined between navigation classes and conceptual
    classes.
•   process link models the association between a «navigation class» and a «process
    class». This process link needs to have associated information about the process
    state, i.e. they may be constraint by an OCL expression over the process state. This
    allows resuming activities within the process under certain conditions.
         +recommendedBooks                                           <<navigation class>>                        <<process class>>
                                                                                            <<process link>>
                                                                         Homepage                                      SignIn



                                                                                                                 <<process link>>
                                                             +shoppingCart        0..1                   +customer
                                                                                                      1
                             <<process class>>   <<process link>> <<navigation class>>                 <<navigation class>>
                                 Checkout                            ShoppingCart                           Customer




                                  <<process link>>
          +products   1..*                                                                              +orders
                                                                          0..*
                                                                                 +shoppingCartItems                 0..*
               <<navigation class>>                                  <<navigation class>>
                     Product                                          ShoppingCartItem                 <<navigation class>>
                                                                                                                Order


                               +product   <<process link>>
                                                                                                   +orderItems       1..*

                                                 <<process class>>                                     <<navigation class>>
                                                    AddToCart                                                  OrderItem




            1..*

        <<navigation class>>
               Book




Fig. 9. UWE Navigation Model (First Step) of the Checkout Process in
www.amazon.com

Process links in the navigation model indicate starting points of process within the
navigation structure (see Fig. 9) . This process link can be bi-directional, such the case of
the process links related to AddToCart and SignIn or the model should include another
«process link» that establishing where the navigation will continue after the process ends,
such as by the CheckoutProcess. The process itself is defined in a separate model (see
next section).
Fig. 9 shows the navigation model after its first construction step. Note that associations
which are not explicitly stereotyped are stereotyped associations of type «navigation
link» (we omit them to avoid overloading). As example of a Amazon product line we
only show the «navigation class» Book to keep the diagram simple as no modeling
differences would be shown by including other product lines, such as classes DVD or
CD. Although the notation for a bidirectional link with a line without arrows is not
intuitive, we prefer to stick to the UML notation.
The second step in the construction of the navigation model consists of the enhancement
of the model by a set of access structures needed for the navigation. In a first step, this
enhancement is partially automated, it consist in introducing indexes, guided-tours and
queries. For each of these constructs UWE defines a stereotyped class «index», «query»
and «guided tour». In Fig. 10 we use icons for indexes (e.g. OrderList) and queries (e.g.
SearchProduct), which are defined by UWE within the UML extension mechanisms
[Koch & Kraus 2001].
                                                            <<navigation class>>
                                                                 Homepage




                      +Recommendations                                                       +YourAccount
                                                                 MainMenu
                                                 +Search
                                                                                   SignIn
                                             ?                                        <<process link>>       AccountInfo
             Book                   SearchProducts
        Recommendation                                                         <<process class>>
                                                                                      SignIn                              +OrderView
                                                           +ViewCart

                                 SelectedResults                          <<process link>>             +PersonalInfo

                                      1..*                              0..1                                           OrderList
                   1..*
        <<navigation class>>     <<navigation class>>        <<navigation class>>     <<navigation class>>
               Book                   Product                  ShoppingCart                 Customer

                                                     <<process link>>                                                      0..*

              <<process link>>                                                                                   <<navigation class>>

                                                  <<process link>>
                                                                                                                        Order
                                                                                                   0..*
                                                                                       CustomerOrders
           <<process class>>                               <<process class>>
             AddToCart                                       Checkout

                                                                                ShoppingCartItems
                                                                                                                       OrdeItems

                                                                                            0..*                           0..*
                                                                                <<navigation class>>            <<navigation class>>
                                                                               ShoppingCartItem                        OrderItem




Fig. 10. UWE Navigation Model (with Access Elements) of the Checkout Process
2 object orientation-copy
2 object orientation-copy
2 object orientation-copy
2 object orientation-copy
2 object orientation-copy
2 object orientation-copy
2 object orientation-copy
2 object orientation-copy

More Related Content

What's hot

FP 301 OOP FINAL PAPER JUNE 2013
FP 301 OOP FINAL PAPER JUNE 2013FP 301 OOP FINAL PAPER JUNE 2013
FP 301 OOP FINAL PAPER JUNE 2013Syahriha Ruslan
 
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMINGFINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMINGAmira Dolce Farhana
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paperfntsofttech
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstractionIntro C# Book
 
Java level 1 Quizzes
Java level 1 QuizzesJava level 1 Quizzes
Java level 1 QuizzesSteven Luo
 
JAVA QUESTIONS FOR INTERVIEW-1
JAVA QUESTIONS FOR INTERVIEW-1JAVA QUESTIONS FOR INTERVIEW-1
JAVA QUESTIONS FOR INTERVIEW-1zynofustechnology
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulationIntro C# Book
 
Java Questions and Answers
Java Questions and AnswersJava Questions and Answers
Java Questions and AnswersRumman Ansari
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstractionIntro C# Book
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answerlavparmar007
 
B.Sc.IT: Semester – V (October – 2012) [Revised Course | Question Paper]
B.Sc.IT: Semester – V (October – 2012) [Revised Course | Question Paper]B.Sc.IT: Semester – V (October – 2012) [Revised Course | Question Paper]
B.Sc.IT: Semester – V (October – 2012) [Revised Course | Question Paper]Mumbai B.Sc.IT Study
 

What's hot (20)

JAVA INTERVIEW QUESTIONS
JAVA INTERVIEW QUESTIONSJAVA INTERVIEW QUESTIONS
JAVA INTERVIEW QUESTIONS
 
PART - 1 Cpp programming Solved MCQ
PART - 1 Cpp programming Solved MCQPART - 1 Cpp programming Solved MCQ
PART - 1 Cpp programming Solved MCQ
 
FP 301 OOP FINAL PAPER
FP 301 OOP FINAL PAPER FP 301 OOP FINAL PAPER
FP 301 OOP FINAL PAPER
 
FP 301 OOP FINAL PAPER JUNE 2013
FP 301 OOP FINAL PAPER JUNE 2013FP 301 OOP FINAL PAPER JUNE 2013
FP 301 OOP FINAL PAPER JUNE 2013
 
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMINGFINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
 
Java Interview Questions -3
Java Interview Questions -3Java Interview Questions -3
Java Interview Questions -3
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
 
Qno 2 (a)
Qno 2 (a)Qno 2 (a)
Qno 2 (a)
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction
 
Java Quiz
Java QuizJava Quiz
Java Quiz
 
Java level 1 Quizzes
Java level 1 QuizzesJava level 1 Quizzes
Java level 1 Quizzes
 
JAVA QUESTIONS FOR INTERVIEW-1
JAVA QUESTIONS FOR INTERVIEW-1JAVA QUESTIONS FOR INTERVIEW-1
JAVA QUESTIONS FOR INTERVIEW-1
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
 
E5
E5E5
E5
 
Java Questions and Answers
Java Questions and AnswersJava Questions and Answers
Java Questions and Answers
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstraction
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
Sample paper i.p
Sample paper i.pSample paper i.p
Sample paper i.p
 
09 Methods
09 Methods09 Methods
09 Methods
 
B.Sc.IT: Semester – V (October – 2012) [Revised Course | Question Paper]
B.Sc.IT: Semester – V (October – 2012) [Revised Course | Question Paper]B.Sc.IT: Semester – V (October – 2012) [Revised Course | Question Paper]
B.Sc.IT: Semester – V (October – 2012) [Revised Course | Question Paper]
 

Viewers also liked

Katalog perfumeryjny nr13
Katalog perfumeryjny nr13Katalog perfumeryjny nr13
Katalog perfumeryjny nr13swiatperfumfm
 
Katalog for home_nr4
Katalog for home_nr4Katalog for home_nr4
Katalog for home_nr4swiatperfumfm
 
Katalog perfumeryjny nr16
Katalog perfumeryjny nr16Katalog perfumeryjny nr16
Katalog perfumeryjny nr16swiatperfumfm
 
Katalog perfumeryjny nr13a
Katalog perfumeryjny nr13aKatalog perfumeryjny nr13a
Katalog perfumeryjny nr13aswiatperfumfm
 
Katalog Make-UP FM nr2
Katalog Make-UP FM nr2Katalog Make-UP FM nr2
Katalog Make-UP FM nr2swiatperfumfm
 

Viewers also liked (8)

Katalog for home
Katalog for homeKatalog for home
Katalog for home
 
Katalog perfumeryjny nr13
Katalog perfumeryjny nr13Katalog perfumeryjny nr13
Katalog perfumeryjny nr13
 
Katalog makeup 6[1]
Katalog makeup 6[1]Katalog makeup 6[1]
Katalog makeup 6[1]
 
Katalog for home_nr4
Katalog for home_nr4Katalog for home_nr4
Katalog for home_nr4
 
Katalog make up_nr2
Katalog make up_nr2Katalog make up_nr2
Katalog make up_nr2
 
Katalog perfumeryjny nr16
Katalog perfumeryjny nr16Katalog perfumeryjny nr16
Katalog perfumeryjny nr16
 
Katalog perfumeryjny nr13a
Katalog perfumeryjny nr13aKatalog perfumeryjny nr13a
Katalog perfumeryjny nr13a
 
Katalog Make-UP FM nr2
Katalog Make-UP FM nr2Katalog Make-UP FM nr2
Katalog Make-UP FM nr2
 

Similar to 2 object orientation-copy

Indus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersIndus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersSushant Choudhary
 
Question 1 To declare a class named A with a generic type, use a. pu.pdf
Question 1 To declare a class named A with a generic type, use a. pu.pdfQuestion 1 To declare a class named A with a generic type, use a. pu.pdf
Question 1 To declare a class named A with a generic type, use a. pu.pdfdbrienmhompsonkath75
 
Java language fundamentals
Java language fundamentalsJava language fundamentals
Java language fundamentalsKapish Joshi
 
Conceitos Fundamentais de Orientação a Objetos
Conceitos Fundamentais de Orientação a ObjetosConceitos Fundamentais de Orientação a Objetos
Conceitos Fundamentais de Orientação a Objetosguest22a621
 
Assignment 7
Assignment 7Assignment 7
Assignment 7IIUM
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guidekrtioplal
 
OOP with Java - continued
OOP with Java - continuedOOP with Java - continued
OOP with Java - continuedRatnaJava
 
Simulado java se 7 programmer
Simulado java se 7 programmerSimulado java se 7 programmer
Simulado java se 7 programmerMiguel Vilaca
 
Will the following code compile- abstract class A { public int do_ (1).docx
Will the following code compile-   abstract class A {   public int do_ (1).docxWill the following code compile-   abstract class A {   public int do_ (1).docx
Will the following code compile- abstract class A { public int do_ (1).docxEvanadoJamesz
 

Similar to 2 object orientation-copy (20)

Indus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersIndus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answers
 
Core java
Core javaCore java
Core java
 
Question 1 To declare a class named A with a generic type, use a. pu.pdf
Question 1 To declare a class named A with a generic type, use a. pu.pdfQuestion 1 To declare a class named A with a generic type, use a. pu.pdf
Question 1 To declare a class named A with a generic type, use a. pu.pdf
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 
Java language fundamentals
Java language fundamentalsJava language fundamentals
Java language fundamentals
 
Uta005
Uta005Uta005
Uta005
 
Inheritance
InheritanceInheritance
Inheritance
 
Questões de Certificação SCJP
Questões de Certificação SCJPQuestões de Certificação SCJP
Questões de Certificação SCJP
 
Conceitos Fundamentais de Orientação a Objetos
Conceitos Fundamentais de Orientação a ObjetosConceitos Fundamentais de Orientação a Objetos
Conceitos Fundamentais de Orientação a Objetos
 
sample_midterm.pdf
sample_midterm.pdfsample_midterm.pdf
sample_midterm.pdf
 
Assignment 7
Assignment 7Assignment 7
Assignment 7
 
Java concurrency questions and answers
Java concurrency questions and answers Java concurrency questions and answers
Java concurrency questions and answers
 
Scjp6.0
Scjp6.0Scjp6.0
Scjp6.0
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guide
 
FSOFT - Test Java Exam
FSOFT - Test Java ExamFSOFT - Test Java Exam
FSOFT - Test Java Exam
 
Unit-3 Practice Programs-5.docx
Unit-3 Practice Programs-5.docxUnit-3 Practice Programs-5.docx
Unit-3 Practice Programs-5.docx
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
OOP with Java - continued
OOP with Java - continuedOOP with Java - continued
OOP with Java - continued
 
Simulado java se 7 programmer
Simulado java se 7 programmerSimulado java se 7 programmer
Simulado java se 7 programmer
 
Will the following code compile- abstract class A { public int do_ (1).docx
Will the following code compile-   abstract class A {   public int do_ (1).docxWill the following code compile-   abstract class A {   public int do_ (1).docx
Will the following code compile- abstract class A { public int do_ (1).docx
 

Recently uploaded

Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 

Recently uploaded (20)

Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 

2 object orientation-copy

  • 1. SCJP 1.6 (CX-310-065 , CX-310-066) Subject: Object Orientation Overloading , overriding , encapsulation, constructor, polymorphism, is-a , has-a relations Total Questions : 66 Prepared by : http://www.javacertifications.net SCJP 6.0: Object Orientation Questions Question - 1 What is the output for the below code ? 1. public class Test{ 2. public static void main (String[] args) { 3. Test t1 = new Test(); 4. Test t2 = new Test(); 5. if(t1.equals(t2)){ 6. System.out.println("equal"); 7. }else{ 8. System.out.println("Not equal"); 9. } 10. } 11. } 1.Not equal 2.equal 3.Compilation fails due to an error on line 5 - equals method not defind in Test class 4.Compilation fails due to an error on lines 3 and 4 resposta Explanation : A is the correct answer. Every class in Java is a subclass of class Object, and Object class has equals method. In Test class equals method is not implemented. equals method of Object class only check for reference so return false in this case. t1.equals(t1) will return true. Question - 2 What is the output for the below code ? 1. public class Test{ 2. public static void main (String[] args) { 3. Test t1 = new Test(); 4. Test t2 = new Test(); 5. if(t1 instanceof Object){ 6. System.out.println("equal"); 7. }else{ 8. System.out.println("Not equal"); 9. } 10. } 11. }
  • 2. 1.Not equal 2.equal 3.Compilation fails due to an error on line 5 4.Compilation fails due to an error on lines 3 and 4 Explanation : B is the correct answer. Every class in Java is a subclass of class Object, so every object is instanceof Object. Question - 3 What is the output for the below code ? public class A { public void printValue(){ System.out.println("Value-A"); } } public class B extends A{ public void printName(){ System.out.println("Name-B"); } } 1. public class Test{ 2. public static void main (String[] args) { 3. B b = new B(); 4. b.printName(); 5. b.printValue(); 6. } 7. } 1.Value-A Name-B 2.Name-B Value-A 3.Compilation fails due to an error on line 5 4.Compilation fails due to an error on lines 4 Explanation : B is the correct answer. Class B extended Class A therefore all methods of Class A will be available to class B except private methods. Question - 4 What is the output for the below code ? public class A {
  • 3. public void printValue(){ System.out.println("Value-A"); } } public class B extends A{ public void printNameB(){ System.out.println("Name-B"); } } public class C extends A{ public void printNameC(){ System.out.println("Name-C"); } } 1. public class Test{ 2. public static void main (String[] args) { 3. B b = new B(); 4. C c = new C(); 5. newPrint(b); 6. newPrint(c); 7. } 8. public static void newPrint(A a){ 9. a.printValue(); 10. } 11. } 1.Value-A Name-B 2.Value-A Value-A 3.Value-A Name-C 4.Name-B Name-C Explanation : B is the correct answer. Class B extended Class A therefore all methods of Class A will be available to class B except private methods. Class C extended Class A therefore all methods of Class A will be available to class C except private methods. Question - 5 What is the output for the below code ? public class A1 { public void printName(){ System.out.println("Value-A"); } } public class B1 extends A1{ public void printName(){
  • 4. System.out.println("Name-B"); } } public class Test{ public static void main (String[] args) { A1 b = new B1(); newPrint(b); } public static void newPrint(A1 a){ a.printName(); } } 1.Value-A 2.Name-B 3.Value-A Name-B 4.Compilation fails Explanation : B is the correct answer. This is an example of polymophism.When someone has an A1 reference that NOT refers to an A1 instance, but refers to an A1 subclass instance, the caller should be able to invoke printName() on the A1 reference, but the actual runtime object (B1 instance) will run its own specific printName() method. So printName() method of B1 class executed. Question - 6 What is the output for the below code ? public class A { public void printName(){ System.out.println("Value-A"); } } public class B extends A{ public void printName(){ System.out.println("Name-B"); } } public class C extends A{ public void printName(){ System.out.println("Name-C"); } } 1. public class Test{ 2. public static void main (String[] args) {
  • 5. 3. A b = new B(); 4. C c = new C(); 5. b = c; 6. newPrint(b); 7. } 8. public static void newPrint(A a){ 9. a.printName(); 10. } 11. } 1.Name-B 2.Name-C 3.Compilation fails due to an error on lines 5 4.Compilation fails due to an error on lines 9 Explanation : B is the correct answer. Reference variable can refer to any object of the same type as the declared reference OR can refer to any subtype of the declared type. Reference variable "b" is type of class A and reference variable "c" is a type of class C but reference variable "c" is a subtype of A class. So it works properly. Question - 7 What is the output for the below code ? public class A { public void printName(){ System.out.println("Value-A"); } } public class B extends A{ public void printName(){ System.out.println("Name-B"); } } public class C extends A{ public void printName(){ System.out.println("Name-C"); } } 1. public class Test{ 2. public static void main (String[] args) { 3. B b = new B(); 4. C c = new C(); 5. b = c; 6. newPrint(b); 7. } 8. public static void newPrint(A a){
  • 6. 9. a.printName(); 10. } 11. } 1.Name-B 2.Name-C 3.Compilation fails due to an error on lines 5 4.Compilation fails due to an error on lines 9 Explanation : C is the correct answer. Reference variable can refer to any object of the same type as the declared reference OR can refer to any subtype of the declared type. Reference variable "b" is type of class B and reference variable "c" is a type of class C. So Compilation fails. Question - 8 What is the output for the below code ? public class C { } public class D extends C{ } public class A { public C getOBJ(){ System.out.println("class A - return C"); return new C(); } } public class B extends A{ public D getOBJ(){ System.out.println("class B - return D"); return new D(); } } public class Test { public static void main(String... args) { A a = new B(); a.getOBJ(); }
  • 7. } 1.class A - return C 2.class B - return D 3.Compilation fails 4.Compilation succeed but no output Explanation : B is the correct answer. From J2SE 5.0 onwards. return type in the overriding method can be same or subtype of the declared return type of the overridden (superclass) method. Question - 9 What is the output for the below code ? public class B { public String getCountryName(){ return "USA"; } public StringBuffer getCountryName(){ StringBuffer sb = new StringBuffer(); sb.append("UK"); return sb; } public static void main(String[] args){ B b = new B(); System.out.println(b.getCountryName().toString()); } } 1.USA 2.Compile with error 3.UK 4.Compilation succeed but no output Explanation : B is the correct answer. Compile with error : You cannot have two methods in the same class with signatures that only differ by return type. Question - 10
  • 8. What is the output for the below code ? public class A1 { public void printName(){ System.out.println("Value-A"); } } public class B1 extends A1{ protected void printName(){ System.out.println("Name-B"); } } public class Test{ public static void main (String[] args) { A1 b = new B1(); newPrint(b); } public static void newPrint(A1 a){ a.printName(); } } 1.Value-A 2.Name-B 3.Value-A Name-B 4.Compilation fails Explanation : D is the correct answer. The access level can not be more restrictive than the overridden method's. Compilation fails because of protected method name printName in class B1. Question - 11 What is the output for the below code ? public class A { private void printName(){ System.out.println("Value-A"); } } public class B extends A{ public void printName(){ System.out.println("Name-B"); } } public class Test{ public static void main (String[] args) { B b = new B();
  • 9. b.printName(); } } 1.Value-A 2.Name-B 3.Value-A Name-B 4.Compilation fails - private methods can't be override Explanation : B is the correct answer. You can not override private method , private method is not availabe in subclass . In this case printName() method a class A is not overriding by printName() method of class B. printName() method of class B different method. So you can call printName() method of class B. Question - 12 What is the output for the below code ? public class A { private void printName(){ System.out.println("Value-A"); } } public class B extends A{ public void printName(){ System.out.println("Name-B"); } } 1. public class Test{ 2. public static void main (String[] args) { 3. A b = new B(); 4. b.printName(); 5. } 6. } 1.Value-A 2.Compilation fails due to an error on lines 4 3.Name-B 4.Compilation fails - private methods can't be override Explanation : B is the correct answer. You can not override private method , private method is not availabe in subclass . printName() method in class A is private so compiler complain about b.printName() . The method printName() from the type A is not visible.
  • 10. Question - 13 What is the output for the below code ? import java.io.FileNotFoundException; public class A { public void printName() throws FileNotFoundException { System.out.println("Value-A"); } } public class B extends A{ public void printName() throws Exception{ System.out.println("Name-B"); } } public class Test{ public static void main (String[] args) throws Exception{ A a = new B(); a.printName(); } } 1.Value-A 2.Compilation fails-Exception Exception is not compatible with throws clause in A.printName() 3.Name-B 4.Compilation succeed but no output Explanation : B is the correct answer. Subclass overriding method must throw checked exceptions that are same or subclass of the exception thrown by superclass method. Question - 14 What is the output for the below code ? import java.io.FileNotFoundException; public class A { public void printName() throws FileNotFoundException { System.out.println("Value-A"); } } public class B extends A{ public void printName() throws NullPointerException{
  • 11. System.out.println("Name-B"); } } public class Test{ public static void main (String[] args) throws Exception{ A a = new B(); a.printName(); } } 1.Value-A 2.Compilation fails-Exception NullPointerException is not compatible with throws clause in A.printName() 3.Name-B 4.Compilation succeed but no output Explanation : C is the correct answer. The overriding method can throw any unchecked (runtime) exception, regardless of exception thrown by overridden method. NullPointerException is RuntimeException so compiler not complain. Question - 15 What is the output for the below code ? public class A { public static void printName() { System.out.println("Value-A"); } } public class B extends A{ public void printName(){ System.out.println("Name-B"); } } public class Test{ public static void main (String[] args) throws Exception{ A a = new B(); a.printName(); } } 1.Value-A 2.Compilation fails-This instance method cannot override the static method from A
  • 12. 3.Name-B 4.Compilation succeed but no output Explanation : B is the correct answer. You cannot override a static method . Compilation fails-This instance method cannot override the static method from A. Question - 16 What is the output for the below code ? public class A { public A(){ System.out.println("A"); } public A(int i){ this(); System.out.println(i); } } public class B extends A{ public B (){ System.out.println("B"); } public B (int i){ this(); System.out.println(i+3); } } public class Test{ public static void main (String[] args){ new B(5); } } 1.A B 8 2.A 5 B 8 3.A B 5 4.B 8 A 5 Explanation : A is the correct answer. Constructor of class B call their superclass constructor of class A (public A()) , which execute first, and that constructors can be overloaded. Then come to constructor of class B (public B (int i)).
  • 13. Question - 17 What is the output for the below code ? public class A { public A(){ System.out.println("A"); } public A(int i){ System.out.println(i); } } public class B extends A{ public B (){ System.out.println("B"); } public B (int i){ this(); System.out.println(i+3); } } public class Test{ public static void main (String[] args){ new B(5); } } 1.A B 8 2.A 5 B 8 3.A B 5 4.B 8 A 5 Explanation : A is the correct answer. Constructor of class B call their superclass constructor of class A (public A()) , which execute first, and that constructors can be overloaded. Then come to constructor of class B (public B (int i)). Question - 18 What is the output for the below code ? public class A { public final void printName() { System.out.println("Value-A"); } }
  • 14. public class B extends A{ public void printName(){ System.out.println("Name-B"); } } public class Test{ public static void main (String[] args) throws Exception{ A a = new B(); a.printName(); } } 1.Value-A 2.Compilation fails-Cannot override the final method from A 3.Name-B 4.Compilation succeed but no output Explanation : B is the correct answer. You cannot override a final method. Compilation fails-Cannot override the final method from A. Question - 19 What is the output for the below code ? public class A { public void printName() { System.out.println("Value-A"); } } public class B extends A{ public void printName(){ System.out.println("Name-B"); super.printName(); } } public class Test{ public static void main (String[] args) throws Exception{ A a = new B(); a.printName(); } }
  • 15. 1.Value-A 2.Name-B Value-A 3.Name-B 4.Value-A Name-B Explanation : B is the correct answer. super.printName(); calls printName() method of class A. Question - 20 What is the output for the below code ? public class A { public void printName() { System.out.println("Name-A"); } } public class B extends A{ public void printName(){ System.out.println("Name-B"); } public void printValue() { System.out.println("Value-B"); } } 1. public class Test{ 2. public static void main (String[] args){ 3. A b = new B(); 4. b.printValue(); 5. } 6. } 1.Value-B 2.Compilation fails due to an error on lines 4 3.Name-B 4.Value-B Name-B Explanation : B is the correct answer. You are trying to use that A reference variable to invoke a method that only class B has. The method printValue() is undefined for the type A. So compiler complain.
  • 16. Question - 21 What is the output for the below code ? public class A { public void printName() { System.out.println("Name-A"); } } public class B extends A{ public void printName(){ System.out.println("Name-B"); } public void printValue() { System.out.println("Value-B"); } } 1. public class Test{ 2. public static void main (String[] args){ 3. A a = new A(); 4. B b = (B)a; 5. b.printName(); 6. } 7. } 1.Value-B 2.Compilation fails due to an error on lines 4 3.Name-B 4.Compilation succeed but Runtime Exception Explanation : D is the correct answer. java.lang.ClassCastException: A cannot be cast to B . You can cast subclass to superclass but not superclass to subclass.upcast is ok. You can do B b = new B(); A a = (A)b; Question - 22 What is the output for the below code ? public class A { public void printName() { System.out.println("Name-A"); }
  • 17. } public class B extends A{ public void printName(){ System.out.println("Name-B"); } public void printValue() { System.out.println("Value-B"); } } 1. public class Test{ 2. public static void main (String[] args){ 3. B b = new B(); 4. A a = (A)b; 5. a.printName(); 6. } 7. } 1.Value-B 2.Compilation fails due to an error on lines 4 3.Name-B 4.Compilation succeed but Runtime Exception Explanation : C is the correct answer. You can cast subclass to superclass but not superclass to subclass.upcast is ok. Compile clean and output Name-B. Question - 23 Which of the following statement is true ? 1.A class can implement more than one interface. 2.An interface can extend another interface. 3.All variables defined in an interface implicitly public, static, and final. 4.All of the above statements are true Explanation : D is the correct answer. All of the above statements are true. Question - 24
  • 18. What is the output for the below code ? 1. public interface InfA { 2. protected String getName(); 3. } public class Test implements InfA{ public String getName(){ return "test-name"; } public static void main (String[] args){ Test t = new Test(); System.out.println(t.getName()); } } 1.test-name 2.Compilation fails due to an error on lines 2 3.Compilation fails due to an error on lines 1 4.Compilation succeed but Runtime Exception Explanation : B is the correct answer. Illegal modifier for the interface method InfA.getName(); only public and abstract are permitted Question - 25 What is the output for the below code ? public class A { public void printName() { System.out.println("Name-A"); } } 1. public class B extends A{ 2. public String printName(){ 3. System.out.println("Name-B"); 4. return null; 5. } 6. } public class Test{ public static void main (String[] args){ A a = new B(); a.printName(); } } 1.Name-B
  • 19. 2.Compilation fails due to an error on lines 2 3.Name-A 4.Compilation fails due to an error on lines 4 Explanation : B is the correct answer. printName() method of class A and printName() method of class B has different return type. So printName() method of class B does not overriding printName() method of class A. But class B extends A so printName() method of class A is available in class B, So compiler complain about the same method name. Method overloading does not consider return types. Question - 26 What is the output for the below code ? public class D { int i; int j; public D(int i,int j){ this.i=i; this.j=j; } public void printName() { System.out.println("Name-D"); } } 1. public class Test{ 2. public static void main (String[] args){ 3. D d = new D(); 4. d.printName(); 5. 6. } 7. } 1.Name-D 2.Compilation fails due to an error on lines 3 3.Compilation fails due to an error on lines 4 4.Compilation succeed but no output Explanation : B is the correct answer. Since there is already a constructor in this class (public D(int i,int j)), the compiler won't supply a default constructor. If you want a no-argument constructor to overload the with-arguments version you already have, you have to define it by yourself. The constructor D() is undefined in class D. If you define explicit constructor then default constructor will not be available. You have to define explicitly like public D(){ } then
  • 20. the above code will work. If no constructor into your class , a default constructor will be automatically generated by the compiler. Question - 27 What is the output for the below code ? public class D { int i; int j; public D(int i,int j){ this.i=i; this.j=j; } public void printName() { System.out.println("Name-D"); } public D(){ } } 1. public class Test{ 2. public static void main (String[] args){ 3. D d = new D(); 4. d.printName(); 5. 6. } 7. } 1.Name-D 2.Compilation fails due to an error on lines 3 3.Compilation fails due to an error on lines 4 4.Compilation succeed but no output Explanation : A is the correct answer. The constructor D() is defined in class D. If you define explicit constructor then default constructor will not be available. You have to define explicitly like public D() {}. Question - 28 Which of the following statement is true about constructor? 1.The constructor name must match the name of the class. 2.Constructors must not have a return type.
  • 21. 3.The default constructor is always a no arguments constructor. 4.All of the above statements are true Explanation : D is the correct answer. All of the above statements are true. Question - 29 What is the output for the below code ? 1. public class A { 2. int i; 3. public A(int i){ 4. this.i=i; 5. } 6. public void printName(){ 7. System.out.println("Name-A"); 8. } 9. } 10. public class C extends A{ 11. } 12. public class Test{ 13. public static void main (String[] args){ 14. A c = new C(); 15. c.printName(); 16. } 17. } 1.Name-A 2.Compilation fails due to an error on lines 10 3.Compilation fails due to an error on lines 14 4.Compilation fails due to an error on lines 15 Explanation : B is the correct answer. Implicit super constructor A() is undefined for default constructor. Must define an explicit constructor. Every constructor invokes the constructor of its superclass implicitly. In this case constructor of class A is overloaded. So need to call explicitly from subclass constructor. You have to call superclass constructor explicitly . public class C extends A{ public C(){ super(7); } } Question - 30 What is the output for the below code ? public class A {
  • 22. public A(){ System.out.println("A"); } } public class B extends A{ public B(){ System.out.println("B"); } } public class C extends B{ public C(){ System.out.println("C"); } } public class Test{ public static void main (String[] args){ C c = new C(); } } 1.A B C 2.C B A 3.C A B 4.Compilation fails Explanation : A is the correct answer. Every constructor invokes the constructor of its superclass implicitly. Superclass constructor executes first then subclass constructor. Question - 31 What is the output for the below code ? public class A { public A(int i){ System.out.println(i); } } 1. public class B extends A{ 2. public B(){ 3. super(6); 4. this(); 5. } 6. } public class Test{ public static void main (String[] args){
  • 23. B b = new B(); } } 1.6 2.0 3.Compilation fails due to an error on lines 3 4.Compilation fails due to an error on lines 4 Explanation : D is the correct answer. A constructor can NOT have both super() and this(). Because each of those calls must be the first statement in a constructor, you can NOT use both in the same constructor. Question - 32 What is the output for the below code ? 1. public class A { 2. public A(){ 3. this(8); 4. } 5. public A(int i){ 6. this(); 7. } 8. } public class Test{ public static void main (String[] args){ A a = new A(); } } 1.8 2.0 3.Compilation fails due to an error on lines 1 4.Compilation fails due to an error on lines 3 Explanation : D is the correct answer. This is Recursive constructor invocation from both the constructor so compiler complain. Question - 33 What is the output for the below code ?
  • 24. 1. public class Test { 2. static int count; 3. public Test(){ 4. count = count +1 ; 5. } 6. public static void main(String argv[]){ 7. new Test(); 8. new Test(); 9. new Test(); 10. System.out.println(count); 11. } 12. } 1.3 2.0 3.1 4.Compilation fails due to an error on lines 2 Explanation : A is the correct answer. static variable count set to zero when class Test is loaded. static variables are related to class not instance so count increases on every new Test(); Question - 34 public class A { public void test1(){ System.out.println("test1"); } } public class B extends A{ public void test2(){ System.out.println("test2"); } } 1. public class Test{ 2. public static void main (String[] args){ 3. A a = new A(); 4. A b = new B(); 5. B b1 = new B(); 6. // insert code here 7. } 8. } Which of the following , inserted at line 6, will compile and print test2? 1.((B)b).test2(); 2.(B)b.test2(); 3.b.test2(); 4.a.test2();
  • 25. Explanation : A is the correct answer. ((B)b).test2(); is proper cast. test2() method is in class B so need to cast b then only test2() is accessible. (B)b.test2(); is not proper cast without the second set of parentheses, the compiler thinks it is an incomplete statement. Question - 35 What is the output for the below code ? public class A { static String str = ""; protected A(){ System.out.println(str + "A"); } } public class B extends A{ private B (){ System.out.println(str + "B"); } } 1. public class Test extends A{ 2. private Test(){ 3. System.out.println(str + "Test"); 4. } 5. public static void main (String[] args){ 6. new Test(); 7. System.out.println(str); 8. } 9. } 1.A Test 2.A B Test 3.Compilation fails due to an error on lines 6 4.Compilation fails due to an error on lines 2 Explanation : A is the correct answer. Test class extends class A and there is no attempt to create class B object so private constructor in class B is not called . private constructor in class Test is okay. You can create object from the class where private constructor present but you can't from outside of the class. Question - 36
  • 26. public class A{ private void test1(){ System.out.println("test1 A"); } } public class B extends A{ public void test1(){ System.out.println("test1 B"); } } public class outputtest{ public static void main(String[] args){ A b = new B(); b.test1(); } } What is the output? 1.test1 A 2.test1 B 3.Not complile because test1() method in class A is not visible. 4.None of the above. Explanation : C is the correct answer. Not complile because test1() method in class A is not private so it is not visible. Question - 37 public class A{ private void test1(){ System.out.println("test1 A"); } } public class B extends A{ public void test1(){ System.out.println("test1 B"); } } public class Test{ public static void main(String[] args){ B b = new B(); b.test1();
  • 27. } } What is the output? 1.test1 B 2.test1 A 3.Not complile because test1() method in class A is not visible 4.None of the above Explanation : A is the correct answer. This is not related to superclass , B class object calls its own method so it compile and output normally. Question - 38 public class A{ public void test1(){ System.out.println("test1 A"); } } public class B extends A{ public void test1(){ System.out.println("test1 B"); } } public class Test{ public static void main(String[] args){ A b = new B(); b.test1(); } } What is the output? 1.test1 B 2.test1 A 3.Not complile because test1() method in class A is not visible 4.None of the above Explanation : A is the correct answer. Superclass reference of subclass point to subclass method and superclass variables.
  • 28. Question - 39 What is the output of the below code ? class c1 { public static void main(String a[]) { c1 ob1=new c1(); Object ob2=ob1; System.out.println(ob2 instanceof Object); System.out.println(ob2 instanceof c1); } } 1.Prints true,false 2.Print false,true 3.Prints true,true 4.compile time error Explanation : C is the correct answer. instanceof operator checks for instance related to class or not. Question - 40 public class C { public C(){ } } public class D extends C { public D(int i){ System.out.println("tt"); } public D(int i, int j){ System.out.println("tt"); } } Is C c = new D(); works ? 1.It compile without any error 2.It compile with error
  • 29. 3.Can't say 4.None of the above Explanation : B is the correct answer. C c = new D(); NOT COMPILE because D don't have default constructor. If super class has different constructor other then default then in the sub class you can't use default constructor Question - 41 public class C { public C(){ } } public class D extends C { public D(int i){ System.out.println("tt"); } public D(int i, int j){ System.out.println("tt"); } } Is C c = new D(8); works ? 1.It compile without any error 2.It compile with error 3.Can't say 4.None of the above Explanation : A is the correct answer. C c = new D(8); COMPILE because D don't have default constructor. If super class has different constructor other then default then in the sub class you can't use default constructor Question - 42 public class C {
  • 30. public C(int i){ } } public class D extends C { public D(){ } } is this code compile without error? 1.yes, compile without error. 2.No, compile with error. 3.Runtime Exception 4.None of the above Explanation : B is the correct answer. We need to invoke Explicitly super constructor(); Question - 43 public class SuperClass { public int doIt(){ System.out.println("super doIt()"); return 1; } } public class SubClass extends SuperClass{ public int doIt() { System.out.println("subclas doIt()"); return 0; } public static void main(String... args) { SuperClass sb = new SubClass(); sb.doIt(); } } What is the output ?
  • 31. 1.subclas doIt() 2.super doIt() 3.Compile with error 4.None of the above Explanation : A is the correct answer. method are reference to sub class and variables are reference to superclass. Question - 44 public class SuperClass { public int doIt(){ System.out.println("super doIt()"); return 1; } } public class SubClass extends SuperClass{ public long doIt() { System.out.println("subclas doIt()"); return 0; } public static void main(String... args) { SuperClass sb = new SubClass(); sb.doIt(); } } What is the output ? 1.subclas doIt() 2.super doIt() 3.Compile with error 4.None of the above Explanation : C is the correct answer. The return type is incompatible with SuperClass.doIt(). Return type of the method doIt() should be int.
  • 32. Question - 45 public class SuperClass { private int doIt(){ System.out.println("super doIt()"); return 1; } } public class SubClass extends SuperClass{ public long doIt() { System.out.println("subclas doIt()"); return 0; } public static void main(String... args) { SuperClass sb = new SubClass(); sb.doIt(); } } What is the output ? 1.subclas doIt() 2.super doIt() 3.Compile with error 4.None of the above Explanation : C is the correct answer. The method doIt() from the type SuperClass is not visible. Question - 46 public class SuperClass { public final int doIt(){ System.out.println("super doIt()"); return 1; } } public class SubClass extends SuperClass{ public long doIt()
  • 33. { System.out.println("subclas doIt()"); return 0; } public static void main(String... args) { SuperClass sb = new SubClass(); sb.doIt(); } } What is the output ? 1.subclas doIt() 2.super doIt() 3.Compile with error 4.None of the above Explanation : C is the correct answer. Cannot override the final method from SuperClass Question - 47 What will be the result of compiling the following code: public class SuperClass { public int doIt(String str, Integer... data)throws Exception{ String signature = "(String, Integer[])"; System.out.println(str + " " + signature); return 1; } } public class SubClass extends SuperClass{ public int doIt(String str, Integer... data) { String signature = "(String, Integer[])"; System.out.println("Overridden: " + str + " " + signature); return 0; } public static void main(String... args) { SuperClass sb = new SubClass(); sb.doIt("hello", 3); } }
  • 34. 1.Overridden: hello (String, Integer[]) 2.hello (String, Integer[]) 3.Complile time error. 4.None of the above Explanation : C is the correct answer. Unhandled exception type Exception. Question - 48 What will be the result of compiling the following code: public class SuperClass { public int doIt(String str, Integer... data)throws ArrayIndexOutOfBoundsException{ String signature = "(String, Integer[])"; System.out.println(str + " " + signature); return 1; } } public class SubClass extends SuperClass{ public int doIt(String str, Integer... data) throws Exception { String signature = "(String, Integer[])"; System.out.println("Overridden: " + str + " " + signature); return 0; } public static void main(String... args) { SuperClass sb = new SubClass(); try{ sb.doIt("hello", 3); }catch(Exception e){ } } } 1.Overridden: hello (String, Integer[]) 2.hello (String, Integer[]) 3.The code throws an Exception at Runtime. 4.Compile with error
  • 35. Explanation : D is the correct answer. Exception Exception is not compatible with throws clause in SuperClass.doIt(String, Integer[]). The same exception or subclass of that exception is allowed. Question - 49 public class SuperClass { public ArrayList doIt(){ ArrayList lst = new ArrayList(); System.out.println("super doIt()"); return lst; } } public class SubClass extends SuperClass{ public List doIt() { List lst = new ArrayList(); System.out.println("subclas doIt()"); return lst; } public static void main(String... args) { SuperClass sb = new SubClass(); sb.doIt(); } } What is the output ? 1.subclas doIt() 2.super doIt() 3.Compile with error 4.None of the above Explanation : C is the correct answer. The return type is incompatible with SuperClass.doIt(). subtype return is eligible in jdk 1.5 for overidden method but not super type return. super class method return ArrayList so subclass overriden method should return same or sub type of ArrayList.
  • 36. Question - 50 public class SuperClass { public List doIt(){ List lst = new ArrayList(); System.out.println("super doIt()"); return lst; } } public class SubClass extends SuperClass{ public ArrayList doIt() { ArrayList lst = new ArrayList(); System.out.println("subclas doIt()"); return lst; } public static void main(String... args) { SuperClass sb = new SubClass(); sb.doIt(); } } What is the output ? 1.subclas doIt() 2.super doIt() 3.Compile with error 4.None of the above Explanation : A is the correct answer. subtype return is eligible in jdk 1.5 for overidden method but not super type return. super class method return List so subclass overriden method should return same or sub type of List. Question - 51 class C{ int i; public static void main (String[] args) { int i; //1 private int a = 1; //2 protected int b = 1; //3
  • 37. public int c = 1; //4 System.out.println(a+b+c); //5 }} 1.compiletime error at lines 1,2,3,4,5 2.compiletime error at lines 2,3,4,5 3.compiletime error at lines 2,3,4 4.prints 3 Explanation : B is the correct answer. The access modifiers public, protected and private, can not be applied to variables declared inside methods. Question - 52 Which variables can an inner class access from the class which encapsulates it. 1.All final variables 2.All instance variables 3.Only final instance variables 4.All of the above Explanation : D is the correct answer. Inner classes have access to all variables declared within the encapsulating class. Question - 53 class c1 { public void m1() { System.out.println("m1 method in C1 class"); } } class c2 { public c1 m1() { return new c1(){ public void m1() { System.out.println("m1 mehod in anonymous class"); }};} public static void main(String a[]) {
  • 38. c1 ob1 =new c2().m1(); ob1.m1(); }} 1.prints m1 method in C1 class 2.prints m1 method in anonumous class 3.compile time error 4.Runtime error Explanation : B is the correct answer. the anonymous class overrides the m1 method in c1.so according to the dynamic dispatch the m1 method in the anonymous is called Question - 54 abstract class vehicle{ abstract public void speed(); } class car extends vehicle{ public static void main (String args[]) { vehicle ob1; ob1=new car(); //1 }} 1.compiletime error at line 1 2.forces the class car to be declared as abstract 3.Runtime Exception 4.None of the above Explanation : B is the correct answer. Abstract method should be overriden otherwise Subclass should be abstract. Question - 55 abstract class C1{ public void m1(){ //1 }} abstract class C2{ public void m2(){ //2 }} 1.compile time error at line1 2.compile time error at line2 3.The code compiles fine
  • 39. 4.None of the above Explanation : C is the correct answer. since the class C2 is abstract it can contain abstract methods Question - 56 class base { base(int c) { System.out.println("base"); } } class Super extends base { Super() { System.out.println("super"); } public static void main(String [] a) { base b1=new Super(); } } 1.compile time error 2.runtime exceptione 3.the code compiles and runs fine 4.None of the above Explanation : A is the correct answer. If super class has different constructor other then default then in the sub class you can't use default constructor. Question - 57 class C1{ public void m1(){ // 1 } } class C2 extends C1{ //2 private void m1(){ } }
  • 40. 1.compile time error at line1 2.compile time error at line2 3.Runtime exception 4.None of the above Explanation : B is the correct answer. extending to assign weaker access not allowed. Overridden method should be more public. Question - 58 class C1 { static interface I { static class C2 { } } public static void main(String a[]) { C1.I.C2 ob1=new C1.I.C2(); System.out.println("object created"); } } 1.prints object created 2.Compile time error 3.Runtime Excepion 4.None of the above Explanation : A is the correct answer. A static interface or class can contain static members.Static members can be accessed without instantiating the particular class Question - 59 class C1 { static class C2 { static int i1; } public static void main(String a[])
  • 41. { System.out.println(C1.C2.i1); } } 1.prints 0 2.Compile time error 3.Runtime exception 4.None of the above Explanation : A is the correct answer. static members can be accessed without instantiating the particular class Question - 60 What will happen when you attempt to compile and run the following code class Base{ protected int i = 99; } public class Ab{ private int i=1; public static void main(String argv[]){ Ab a = new Ab(); a.hallow(); } abstract void hallow(){ System.out.println("Claines "+i); } } 1.Compile time error 2.Compilation and output of Claines 99 3.Compilation and output of Claines 1 4.Compilation and not output at runtime Explanation : A is the correct answer. Abstract and native methods can't have a body: void hallow() abstract void hallow() Question - 61 public class A extends Integer{ public static void main(Sring[] args){ System.out.println("Hello");
  • 42. } } What is the output? 1.Hello 2.Compile Error 3.Runtime 4.None of the above Explanation : B is the correct answer. final class can't be extended. Integer is final class. Question - 62 which statement is correct ? 1.A nested class is any class whose declaration occurs within the body of another class or interface 2.A top level class is a class that is not a nested class. 3.A top level class can be private 4.none of the above Explanation : A and B is the correct answer. A nested class is any class whose declaration occurs within the body of another class or interface A top level class is a class that is not a nested class. Question - 63 Constructor declarations can be include the access modifiers? 1.public 2.protected 3.private 4.All of the above Explanation : D is the correct answer. constructor declarations may include the access modifiers public, protected, or private Question - 64
  • 43. private class B { public static void main(String[] args){ System.out.println("DD"); B b = new B(); } } What is the output ? 1.DD 2.Compile Error. 3.Runtime Exception 4.None of the above. Explanation : B is the correct answer. Only public, abstract and final is permitted for class modifier. Question - 65 public class Point { int x = 1, y = 1; abstract void alert(); } Is the code compile without error ? 1.compile without error 2.compile with error , because class should be abstract. 3.Can't say 4.None of the above. Explanation : B is the correct answer. If there is any abstract method in a class then the class should be abstract. Question - 66 abstract class Point { int x = 1, y = 1; abstract void alert(); } public class A{ public static void main(String[] args){ Point p = new Point();
  • 44. } } What is the output ? 1.compile without error 2.compile with error. 3.Can't say 4.None of the above. Explanation : B is the correct answer. abstract class can't be instantiated.
  • 45. Modeling Web Business Processes with OO-H and UWE1 NORA KOCH AND ANDREAS KRAUS Ludwig-Maximilians-Universität München. Germany CRISTINA CACHERO AND SANTIAGO MELIÀ Universidad de Alicante, Spain ________________________________________________________________________ Business processes, regarded as heavy-weighted flows of control consisting of activities and transitions, pay an increasingly important role in Web applications. In order to address these business processes, Web methodologies are evolving to support its definition and integration with the Web specific aspects of content, navigation and presentation. This paper presents the model support provided for this kind of processes by both OO-H and UWE. For this support both approaches use UML use cases and activity diagrams and provide appropriate modeling extensions. Additionally, the connection mechanisms between the navigation and the process specific modeling elements are discussed. As a representative example to illustrate our approach we present the requirements, analysis and design models for the amazon.com Website with focus on the checkout process. Our approach includes requirements and analysis models shared by OO-H and UWE and provides the basis on which each method applies its particular design notation. Categories and Subject Descriptors: H.5.4 [Information Interfaces and Presentation]: Hypertext/Hypermedia – Architecture; Navigation; User Issues; D.2.2 [Software Engineering]: Design Tools and Techniques – Object-oriented Design Methods; D.2.1 [Software Engineering]: Requirements Specification – Methodologies; I.6.5 [Computing Methodologies]: Simulation and Modeling – Model Development General Terms: Design, Experimentation, Human Factors Additional Key Words and Phrases: Web Engineering, UML, Visual Modeling, Process Modeling, UML Profile ________________________________________________________________________ 1. INTRODUCTION Business processes, regarded as heavy-weighted flows of control consisting of activities and transitions [UML 2003], have always paid an important role in software development methods, to the point that many process proposals include the definition of an explicit view (the process view) in order to address their complexity. However, such processes have been only tangentially tackled in most existing Web Application modeling approaches [Retschitzegger & Schwinger 2000]. This reality is partly due to the fact that most of these methods were born with the aim of successfully modeling Information Systems (IS) [Baresi et al. 2001, Schwabe et al. 2001, Ceri et al. 2002, De Troyer & Casteleyn 2001, Gomez et al. 2001, Koch & Kraus, 2002], which ‘store, retrieve, 1 This work has been partially supported by the European Union within the IST project AGILE – Architectures for Mobility (IST-2001-32747), the German BMBF-project GLOWA-Danube, and the Spain Ministry of Science and Technology, project number TIC2001-3530-C02-02. Authors' addresses: Nora Koch and Andreas Kraus, Ludwig-Maximilians-Universität München, Germany, http://www.pst.informatik.uni-muenchen.de, {kochn,krausa}@informatik.uni-muenchen.de. Cristina Cachero and Santiago Meliá, Universidad de Alicante, España, http://www.ua.es, {ccachero,santi}@dlsi.ua.es.
  • 46. transform and present information to users. [They] Handle large amounts of data with complex relationships, which are stored in relational or object databases’ [Korthaus 1998]. Therefore, Web modeling approaches have intensively worked on (1) the definition of suitable constructs to address the user navigation through the domain information space and (2) the inclusion of mechanisms to model the change in such information space through the invocation of synchronous retrieval and update operations. In contrast, requirements posed on modern Web applications imply to regard them not only as Information Systems but also as Business Systems, that is, applications centered on goals, resources, rules and, mainly, the actual work in the business (business processes). Workflow management systems, which have proven successful for the definition and control of these processes, fall short however when faced to the problem of defining rich business-enabled Web interfaces that, aware of the underlying workflow, support and guide the user through it, preserving at the same time the hypertext flexibility. The hypermedia community, conscious of this gap, has been working for some time on the extension of Web modeling methods (which are specially suited to deal with the complexity of Web interfaces) with new mechanisms that permit the definition and integration of lightweight business processes with the rest of the views. This extension may be done following at least two different approaches: on one hand, traditional content, navigation and/or presentation models may be enriched to capture this workflow. Examples in this sense include Araneus2 [Atzeni & Parente 2001], which defines the mechanisms to allow the grouping of activities into phases, Wisdom [Nunes & Cunha 2000], which proposes a UML extension that includes the use of a set of stereotyped classes, or WebML [Brambilla et al. 2002] which enriches the data and the hypertext models to define lightweight web-enabled workflows. On the other hand, additional models may be defined, and its connection with the pre-existing content, hypertext and/or presentation views established. This has been the approach jointly followed by UWE and OO-H, as we will present in this paper. Our aim in this paper has been therefore to find a common set of modeling concepts that suffices to define sound, non-trivial business processes and that could be equally useful in other existing methodologies. In order to define the necessary constructs and modeling activities, we have decided to adhere to well known object-oriented standards, namely to the semantics and notation provided by UML. Using UML to model business processes is not new; authors like [Nunes & Cunha 2000, Markopoulos 2000] have already acknowledged its feasibility and excellence. From the set of modeling techniques provided by the UML, the activity diagram is the most suitable mechanism to model the business workflow, and so has been adopted by both OO-H and UWE to define the different processes. In this diagram, activity states represent the process steps, and transitions capture the process flow, including forks and joins to express sets of activities that can be processed in arbitrary order. In order to reach our goal, this work is organized as follows: Sections 2 and 3 present the analysis steps, equal for both methodologies. Section 4 and Section 5 describe the design steps for OO-H and UWE, respectively. Last, Section 6 outlines conclusions while Section 7 proposes future lines of research. In order to better illustrate the whole approach, a simplified view of the well-known Amazon checkout process (http://www.amazon.com) is going to be employed all along the paper.
  • 47. 2. THE ROLE OF BUSINESS PROCESSES IN REQUIREMENT ANALYSIS The inclusion of a business process in any Web modeling approach affects every stage of development, from requirements analysis to implementation. Regarding requirements analysis, whose goal is the elicitation, specification and validation of the user and customer needs, this activity includes the detection of both functional and non-functional requirements, both of which may get affected by process concerns. Although there is a lack of a standardized process supporting requirements analysis, best practices in the development of general software applications provide a set of techniques. A recent comparative study [Escalona & Koch 2003] about requirements engineering techniques for the development of Web applications showed that use case modeling is the most popular technique proposed for the specification of requirements while interviewing is the most used technique for the capture of those requirements. These results are not surprising; traditional software development requires interviewing as an intuitive and widely used procedure to guide a “conversation with a purpose” [Kahn & Cannell 1957], and use cases are a well known approach for graphical representation and description of requirements suggested by [Jacobson et al. 1992]. Use case modeling is a powerful formalism to express functional requirements of business intensive – Web or non-Web – applications. In this sense, OO-H and UWE are object-oriented approaches (partially and completely based on UML, respectively) and both of them include the use case modeling technique to gather the requirements of Web applications. To define a use case model the first step is to identify actors and the corresponding use cases of the application. Such a use case model usually includes a use case diagram which is usually enough to describe the functionality of simple systems, such as of Web information systems. On the other hand, Web applications including business processes require a more detailed description of these – more complex – sequences of actions. In order to address this additional complexity as it is shown in the next section, both approaches propose the use of UML activity diagrams. In our running example we have identified two actors that play a relevant role in the checkout process: the NonRegisteredUser and the Customer. The non-registered user can – among other activities – search and select products, add products to the shopping cart and login into the Amazon Web application. The Customer inherits from the NonRegisteredUser and is allowed among other things (after logged-in) to start the checkout process. Fig. 1 presents a partial view of the use case diagram corresponding to the Amazon Web application. For the sake of simplicity, in this diagram we have centered on the use cases that are directly related to the selection of items and the checkout process, therefore ignoring others such as, just to name a few, AddToWishList, CheckOrder or ReturnItems, which are however also relevant tasks from the user point of view. In this diagram we can observe how a NonRegisteredUser may select product items. Such selection may be performed using a system search capability, which is modeled by means of an inheritance relationship between the use cases SelectProductItems and SearchProductItems. Also, this user may decide to add any selected product to his
  • 48. shopping cart. This fact is modeled by means of an «extend» dependency between the use case AddToShoppingCart and the SelectProductItems use case. <<extend>> <<navigation>> AddToShoppingCart SelectProductItems <<navigation>> <<navigation>> NonRegisteredUser SearchProductItems ViewCart SignIn <<extend>> Customer <<include>> Checkout SendInvoice Fig. 1. Use Case Diagram of the Checkout Process in www.amazon.com At any time, the user may decide to ViewCart, in order to check the items included so far in his shopping basket. Also, he could decide to personalize her view, for what he would have to SignIn. Furthermore, only a signed-in user may proceed to checkout. This situation is again modeled by means of an «extend» dependency between the use cases SigIn and Checkout. The completion of the checkout process implies the sending of a notification with the invoice associated with the purchase. We have modeled this action as a use case that is related («include» dependency) to the Checkout use case. The Customer may also wish to be sent an additional invoice at any time after the purchase; in Fig. 1 this fact is captured by means of an association between the actor Customer and the SendInvoice use case. If we now analyze the inner flow of control of each defined use case in the context of the Amazon Web application, we may note how some flows are trivial from the business point of view, as they only express navigation activities. For this kind of use cases, we propose the use of a «navigation» stereotype, as defined in [Baresi et al. 2001]. Others, on the contrary, imply a complex flow of control, and require further refinements, as we will show next. 3. ANALYSIS PHASE IN PROCESS-AWARE WEB APPLICA- TIONS Once the requirements have been clearly stated, both in OO-H and UWE the next step consists on the analysis of the problem domain. This analysis phase has traditionally involved in both methods the definition of a conceptual model reflecting the domain structure of the problem. This model however does not provide the mechanisms to specify process concerns. That is the reason why we have included a new model, the
  • 49. process model that enriches this analysis phase. Next we will show how these models can be applied to our running example. 3.1. CONCEPTUAL MODEL The definition of a conceptual model by means of a UML class diagram is a common feature in most Web modeling approaches, including UWE and OO-H. Back to our example, we have defined a common conceptual model, materialized in a UML class diagram that is depicted in Fig. 2. ConceptualModel UserModel ShoppingCart Customer name add() creditCard 1..* 0..1 checkout() Book 1 * Product ShoppingCart DVD name Item price 1 quantity * * CD * Address OrderItem +deliveryAddress street quantity zip-code 1 0..1 country * 1 Order +invoiceAddress orderID 1 invoiceNumber sendInvoice() Fig. 2. Conceptual Model of the Checkout Process in www.amazon.com This class diagram is made up of two packages: the User Model and the Conceptual Model. The first one includes the structures directly related to the individual user, such as the ShoppingCart or the different Addresses provided by each Customer. The Conceptual Model on the other hand maintains information related to domain objects such as Products and Orders. Note how this diagram is a simplification of the actual Amazon domain model, and reflects only a possible subset of constructs that are needed to support the checkout process. In this diagram we can observe how a customer (which may be anonymous before logging-in in the system) has a ShoppingCart, which is made-up of ShoppingCartItems (each one associated with a Product, which may be a Book, a DVD or a CD, just to name a few). On the other hand each customer has a set of predefined Addresses that, once the order has been created, are used both to send the different items and to set the invoice address. When the customer decides to checkout, the system creates a new Order and converts the ShoppingCartItems into OrderItems. When the order is finally placed, an invoiceNumber is associated to the order. The conceptual model is not well suited to provide information on the underlying business processes that drive the user actions through the application. For this reason, OO-H and UWE have included a process model that is outlined in the next two sections.
  • 50. 3.2. PROCESS MODEL Process modeling (also called task modeling) stems from the Human Computer Interaction (HCI) field. Different UML notations have already been proposed for process modeling. Wisdom [Nunes & Cunha 2000] is a UML extension that proposes the use of a set of stereotyped classes that make the notation not very intuitive. Markopoulus [Markopoulos 2000] instead makes two different proposals: an UML extension of use cases and another one based on statecharts and activity diagrams. Following this last trend, we have opted to use activity diagrams, due to their frequency of use and their flexibility to model flows. An activity diagram is a special case of a state diagram in which all (or at least most) of the states are actions or subactivity states and in which all (or at least most) of the transitions are triggered by completion of the actions or completion of the subactivities in the source states. The entire activity diagram is attached (through the model) to a UML classifier, such as a use case, or to a package, or to the implementation of an operation [UML 2003]. The UML modeling elements for a process model are activities, transitions and branches. Activities represent atomic actions of the process and they are connected with each other by transitions (represented by solid arrows) and branches (represented by diamond icons). The branch conditions govern the flow of control and in the analysis process model they can be expressed in natural language. As stated before, both OO-H and UWE use activity diagrams to complement the domain model and define the inner flow of control of non trivial use cases. In Fig. 3 an activity diagram representing the simplified flow of control of the Amazon Checkout process (depicted as a non-navigational use case in Fig. 1) is presented. [ error ] SignIn [ newCustomer ] [ returningCustomer ] [ error ] AddNewCustomer [ change ] SetOptions newCustomer : Customer [ newCustomer ] [ returningCustomer ] SetPassword PlaceOrder exit/ delete Items of ShoppingCart newOrder : Order SendInvoice Fig. 3. Process Model of the Checkout Process in www.amazon.com
  • 51. In this diagram we can observe how a SignIn subactivity starts the process. Next, depending on whether the user is new in the system or not, he can be added to the system or directly driven to the SetOptions subactivity state that permits the user to establish every purchase option (see ). Once this activities has been completed, the user may set his password (only if he is a new customer), place the order and be sent an invoice with the purchase details. Subactivity states, as shown in the diagram of Fig. 3, express the hierarchical decomposition of a process. A subactivity state invokes another activity diagram. When a subactivity state is entered, the nested activity graph is executed. A single activity graph may be invoked by many subactivity states meaning that activity diagrams can be (re- )used within the context of different processes and sub processes (i.e. subactivities). In our example, Fig. 4 shows the flow of control of the SetOptions subactivity state represented by a UML activity diagram. This diagram includes activities for the user to enter shipping and payment options, wrapping options and confirm the cart items before placing the order. In the checkout process only options not already set before e.g. in previous checkouts or those that the user explicitly wants to change are triggered in the process context. [ not set or change ] [ not set or change ] [ not set or change ] [ not set or change ] ConfirmItems SetWrapOptions SetShippingOptions SetPaymentOptions Fig. 4. Activity Diagram of the SetOptions Process in www.amazon.com In Fig. 3 we can also observe how the use and extend dependencies defined in the use case diagram of Fig. 1 influence the flow of control of the process, and are materialized in the inclusion of complementary activities (see e.g. SendInvoice) and subactivity states (e.g. SignIn) that, as suggested by such dependencies, play a role in the definition of the checkout process. Finally, the activity diagram associated with a given Web-aware business process can also be enriched with object flows indicating objects that are relevant at analysis level as input and output to crucial activities. In the example a new Customer is created as result of the AddNewCustomer activity and a new Order object is created as result of the PlaceOrder activity. Once this analysis model has been defined, at least two approaches can be followed: • The definition of a navigation model that is driven by a (refined) process flow model. This tight integration between process and navigation expresses the
  • 52. interplay between the user interface design and the steps inferred from the process definition. • The definition of a navigation model that is enriched to reflect a set of integration points, that is, points in which the user may leave the navigation view to enter a process design view. Next, we will show how OO-H and UWE, each implements one of these approaches, and how in spite of this fact, analysis models are still fully reusable and a common ground for discussion. 4. DESIGN OF WEB BUSINESS PROCESS WITH OO-H OO-H [Cachero 2003; Gomez et al. 2001] is a generic approach, partially based on the Object Oriented paradigm, that provides the designer with the semantics and notation necessary for the development of personalized Web-based interfaces. Like many other approaches, the OO-H modeling process is driven by the set of identified user requirements, and explicitly supports the definition of different user interfaces depending on the actor that is accessing the application. The whole method is supported by the Case tool VisualWADE, a modeling environment that includes a set of model compilers to provide automatic code generation capabilities. From the six complementary views included in OO-H (requirement, conceptual, process, navigation, presentation and architectural), in this article we will center on the process view. This process view is based, as stated above, on a set of activity diagrams that supplement the information contained in the domain model. In order to make this connection between both models explicit, both class and activity diagrams are refined during the design phase, and the correspondence between the process constructs and the domain constructs is set. On this refined process view, a set of mapping rules can be applied in order to get a default navigation view and assure the traceability between both models, as will be explained in section 4.2. 4.1. PROCESS MODEL REFINEMENT OO-H bases the process refinement on the concept of service, regarded as an interface whose purpose is collect a set of operations that constitute a coherent service offered by classifiers, and so provide a way to partition and characterize groups of operations [UML 2003]. Services in OO-H can be classified according to several orthogonal characteristics, among which we outstand (1) synchronicity, (2) activating agent, (3) granularity (number of operations supporting the service) and (4) transactionality [Cachero 2003]. OO-H centers on synchronous, user-activated services. Inside this group, OO-H is well suited to provide an arbitrary complex interface to single (either transactional or not) services, where by single we mean services supported by exactly one underlying class operation. That is the case of Create, Delete and Update operations, which are at the core of typical single, transactional (ACID) services. On the other hand, the definition of an interface for a compound service, which involves more than one domain operation, presents special challenges from the user interface
  • 53. modeling point of view. In this kind of services, the user interface is responsible for guiding the user through the different domain operations following a predefined flow of control, which may involve both activity and information dependencies. A checkout service such as the one included in Amazon is, from the OO-H point of view, a compound, non-transactional service. For this service, a possible activity diagram representing the system flow of control has been already presented in Fig. 3. In order to further refine the analysis process view, we must take into account detailed class properties. A new class diagram with a more exhaustive list of attributes and methods is shown in Fig. 5. Note how this diagram can be regarded as a possible evolution of the one presented in Fig. 2. Customer ShoppingCart cName ID emailAddress Book CD DVD passwd addItem() 1..* 0..1 checkout() login() deleteItems() new() setPasswd() 1..1 * Product ShoppingCartItem pName 1..1 * quantity price + * Address OrderItem quantity street * 1..1 zip-code confirmItem() country 1..1 + Order orderID invoiceNumber shippingSpeed new() setShippingAddress() 1..1 setBillingAddress() setPaymentOptions() placeOrder() setWrappingOptions() sendInvoice() Fig. 5. OO-H Refined Class Diagram of the Checkout Process in www.amazon.com Taking into account the underlying operations, it is possible to construct a more detailed activity diagram, such as the one presented in Fig. 6. In this figure we observe several examples of refinements allowed in OO-H at this level of abstraction: • Some subactivity states may be redefined as call states, implying that a single operation (at most) gives them support. That is the case of the SignIn subactivity state (see Fig. 3) that has been now redefined as a call state. • Some call states may be merged under a common subactivity state. This feature is specially useful when a transaction is detected which involves several call states. In our example, we have considered that PlaceOrder and SendInvoice are related activities (in the checkout process the invoice is automatically sent after the order has been placed), and that an error while sending the invoice implies that the order cannot be placed, because the user would lack the necessary notification. Therefore we have defined a transactional subactivity state that includes both call states (see Fig. 6).
  • 54. Call states may be complemented (if necessary) with information regarding the domain operation that gives them support in a do section. For example, the transactional activity SetPasswd() states in the refined activity diagram that this activity is supported by the operation setPasswd(in passwd:String), which belongs to the Customer class. Note how this fact could also have been modelled by means of swimlanes added to the diagram. • A new «transactional» stereotype must be applied to the different activities. This stereotype reflects the transactional character of both call states and subactivity states. A transactional activity/subactivity state presents the classical ACID properties. Furthermore, transactional subactivity states imply that every underlying activity or subactivity state belongs to the same transaction. On the contrary, a non- transactional subactivity state does not pose any requirement over the elements included. Back to our example, the SignIn activity has been defined as non- transactional. In our approach this fact implies that the activity does not need logic support, as it might be modelled with the aid of filters and navigation constructs, as we will show in section 4.2 <<nonTransactional>> [ Error ] SignIn do/ Customer.login() <<transactional>> [ newCustomer ] AddNewCustomer [ Error ] do/ Customer.new(eMail) [ returningCustomer ] <<nonTransactional>> SetOptions entry/ Order.new() <<transactional>> [ newCustomer ] SetPasswd do/ Customer.setPasswd(passwd) [ returningCustomer ] <<transactional>> PlaceOrder exit/ ShoppingCart.deleteItems() Fig. 6. OO-H Refined Activity Diagram of the Checkout Process in www.amazon.com For the sake of simplicity, in Fig. 6 we have hidden other possible refinements, such as for example the set of OCL guard conditions that may be associated with the transitions, the OCL formulae that may be associated to non-transactional activities or the detailed flow of objects among activities and/or subactivity states, which would also be relevant at this stage of the model and from which it would be possible to infer certain parameter dependencies during the invocation of the underlying methods if necessary.
  • 55. 4.2. DEFAULT NAVIGATION MODEL As we have stated before, OO-H redefines call states so that they can be mapped to underlying domain constructs. In order to support this mapping, the UML metamodel must be conservatively extended to capture this connection between OO-H activities (a specialization of the UML activity construct) and conceptual operations and/or classes. The reason for this connection is that, as we will see next, in this way it is possible to automatically generate a default navigation view that not only speeds up the development cycle but also assures the interface guidance and support to this process. The navigation model in OO-H is defined by means of a Navigation Access Diagram (NAD). This diagram is made up of collections (depicted as an inverted triangle and which capture in OO-H the menu concept), navigation targets (navigation subsystems depicted with a package symbol), navigation classes (views on conceptual classes, depicted with the class symbol) and navigation links (which describe the paths the user may follow through the system and that are depicted with the arrow symbol). Navigational links, being a central construct in OO-H and the core of the navigation view, have several relevant characteristics associated: • Type. It can be set to (1) requirement link, which determines the beginning of the user navigation through the diagram, (2) traversal link, which defines navigation paths between information structures or (3) service link, which provides an arbitrarily complex user interface to assign values to the underlying in operation parameters and/or define the visualization of the operation results (out parameters). • Activating Agent: can be set to user (depicted as a solid arrow) or system (depicted as a dotted arrow) • Navigation effect: can be set to origin (depicted as a hollow arrow end) or destination (filled arrow end). Filters, defined as expressions loosely based on OCL and which are associated to links. In these expressions, a question mark (?) symbol represents user input. All these symbols can be observed in Fig. 7. This figure depicts a possible OO-H navigation model corresponding to our checkout running example. Fig. 7 also illustrates how the process view provides the necessary information to generate a default navigation view, enabling in this way the automatic generation of a navigation model out of a process model. In order to get this navigation model, we have applied a predefined set of mapping rules, which can be summarized as follows: In Table 1 we observe how non-transactional activities are transformed into navigational links, which will need to be further refined with a navigation filter that completes the activity specification. Transactional activities and/or transactional subactivity states on the contrary require the support of an underlying domain operation that hides and preserves such transactional character. Operations are accessed at NAD level by means of service links. On the other hand, non-transactional subactivity states can be regarded as navigational subsystems, and therefore materialized in a OO-H Navigation target associated with each of the defined subsystems. Transitions trivially map to traversal links, which are by default activated by the user and cause a change of user view.
  • 56. Activity Diagram Element NAD diagram element Non-Transactional Activity Navigational link refined with precondition filter Transactional Activity Service link associated with a Navigational class Transition Navigation target Subactivity Service link associated with a Navigational class Branch Traversal link Merge Collection from which a set of Traversal links with exclusive filters departs. Split-Join Collection at which a set of Traversal links with no filters arrives. Table 1. Mapping Rules between Process View and Navigation View in OO-H Branches can be regarded as menus where only one option is available at a time. This fact is modeled in OO-H by means of a collection construct and a set of traversal links, each one with an exclusive filter associated. Merge constructs, on the other hand, cause the generation of a collection that is the target for a set of automatic traversal links. Last, the synchronization bars (split-join constructs) cause the generation of a default path that traverses the concurrent activities in arbitrary order (namely from top to bottom and from left to right). SignIn[precond:Context.emailAdress=? and Context.password = ? COL1 AddNewCustomer[precond: context.emailAddress=?] CustomerView: Customer new() SetOptions DN3 COL3 [precond: Context.passwd->isEmpty()] CustomerView2: Customer Precond:Context.password->notEmpty()] setPasswd() PlaceOrder DN6 Fig. 7. NAD Diagram for Customer Identification in the Checkout Process As an illustrating example, and looking back at the activity diagram of Fig. 6, we observe that the first constructor that appears is the SignIn non-transactional call state. This activity is materialized in Fig. 7 in a navigational link with an associate filter (OCL
  • 57. formula) that implements a query over the underlying information repository. After this query has been performed, and depending on whether the user is new or a returning customer, a collection construct (col1, see Fig. 7) drives us either to a new() method or to a SetOptions navigation target respectively. Assuming that the user states he is new, he will follow the AddNewCustomer link, which first of all will demand the user to enter an emailAddress that is gathered in an OO-H predefined context object. While the customer navigational class and the associated service link have been generated automatically, the filter is a refinement added by the designer on the default model to correctly capture the Amazon interface. This email value will be then used to provide a value to one of the parameters defined for the new() service that can be accessed through the CustomerView. When the underlying operation returns the control, and assuming that everything is OK, a system automatic traversal link (dotted arrow) drives the user to the SetOptions Navigation Target. This diagram also shows the association between activities and classes and/or domain operations. As an example, the association of the AddNewCustomer activity of Fig. 6 with the new() operation in the Customer class has caused the inclusion of a CustomerView and a service link associated (see Fig. 7). If we now enter the SetOptions navigation target, generated after the homonim subactivity state, we may observe how all options may be performed in parallel. Navigationally speaking, and in order to assure that the completion of all the parallel activities is possible, OO-H infers a navigation path that sequentially traverses the constructs associated with each one of these activities (see Fig. 8). OrderItem: OrderItem Order1: Order Order2: Order Order3: Order confirmItem() setWrappingOptions() setShippingAddress() setPaymentOptions() COL3 COL4 COL5 COL6 LR9 PlaceOrder:: Order Fig. 8. NAD Diagram Corresponding to the SetOptions Subactivity State Once the whole navigation model has been refined, a default presentation model can be automatically generated in the OO-H development environment. In order to complete the application specification, OO-H provides a presentation model that is partly-based on the design models presented so far and that falls out of the scope of this paper.
  • 58. 5. DESIGN OF WEB BUSINESS PROCESS WITH UWE The UWE methodology [Koch & Kraus 2002] is an object-oriented and iterative approach based on the standard UML. The main focus of UWE is the systematic design followed by a semi-automatic generation of Web applications. To support the systematic design the CASE-tool ArgoUWE (an extension of ArgoUML2) is currently being implemented. The semi-automatic generation of Web applications is supported by the UWEXML – a model-driven Code Generator for deployment to an XML publishing framework. Both are part of the OpenUWE development environment. The common language for data interchange within this architecture is defined by the UWE metamodel defined as a conservative extension of the UML metamodel and therefore a MOF (Meta Objects Facility) compatible metamodel [Koch & Kraus 2003]. The UWE metamodel elements are also the basis for the UWE notation which is defined as a “lightweight” UML profile, i.e. a UML extension based on the extension mechanisms defined by UML. The UWE profile includes a set of Web specific modeling elements for navigation, presentation, process and personalization. In this section we will focus on the notation used by UWE for business processes and the development steps to build such category of applications. The UWE design approach for Web business process, in the same way as OO-H does, is based on the models built during the analysis phase, i.e. the conceptual model and the process model, both presented in Section 4. It uses standards not only to build the analysis models, but UWE also sticks to the UML in this design phase. In this phase UWE selects the appropriate diagram types and proposes to enrich the UWE Profile with a couple of modeling elements, improving in this way the expressiveness of the UML constructs for the Web domain. In the treatment of business processes UWE differs from OO-H by not mapping the process model to the navigation model but additionally introducing specific process classes that are part of a separate process model with a clear interface to the navigation model. Design of Web business applications following the UWE methodology requires the following activities: First, the refinement of the conceptual model adding attributes and methods to the already identified classes. We will neither detail this refinement process nor depict the resulting diagram in this work, as these are well known activities done in object-oriented development. Second, the integration of the processes in the navigation model to indicate browsing possibilities. Third, the refinement of the process model building a process structure and a process flow view. Last but not least, the presentation model is built based on the navigation and process models showing how the navigation paradigm and the business processes are combined. 5.1. INTEGRATION OF PROCESSES IN THE NAVIGATION MODEL Navigation modeling activities in UWE comprise the construction of the navigation model in two steps. First, the objective is to specify which objects can be visited by navigation through the application. Incorporating to this diagram additional constructs it 2 www.tigris.org
  • 59. is shown how the user can reach the navigation elements. The navigation model is represented by a stereotyped class diagram. It includes the classes of those objects which can be visited by navigation through the Web application, such as classes Product, ShoppingCart, Order, Customer, Book, etc. UWE provides a set of guidelines and semi- automatic mechanisms for modeling the navigation of an application, which are detailed in previous works [Koch and Kraus 2002]. This automation as well as model checking is supported by the CASE tool ArgoUWE [Zhang 2002]. UWE defines a set of modeling elements used in the construction of the navigation model. For the first step the «navigation class» and the «navigation link» have been used until now to model nodes and links. For modeling process-aware Web applications we introduce two additional stereotypes «process class» and «process link», which are defined with the following semantic: • process class models a class whose instances are used by the user during execution of a process. It is possible to define a mapping function between «process class» classes and use cases (those use cases not stereotyped as «navigation») in a similar way to the mapping function defined between navigation classes and conceptual classes. • process link models the association between a «navigation class» and a «process class». This process link needs to have associated information about the process state, i.e. they may be constraint by an OCL expression over the process state. This allows resuming activities within the process under certain conditions. +recommendedBooks <<navigation class>> <<process class>> <<process link>> Homepage SignIn <<process link>> +shoppingCart 0..1 +customer 1 <<process class>> <<process link>> <<navigation class>> <<navigation class>> Checkout ShoppingCart Customer <<process link>> +products 1..* +orders 0..* +shoppingCartItems 0..* <<navigation class>> <<navigation class>> Product ShoppingCartItem <<navigation class>> Order +product <<process link>> +orderItems 1..* <<process class>> <<navigation class>> AddToCart OrderItem 1..* <<navigation class>> Book Fig. 9. UWE Navigation Model (First Step) of the Checkout Process in www.amazon.com Process links in the navigation model indicate starting points of process within the navigation structure (see Fig. 9) . This process link can be bi-directional, such the case of
  • 60. the process links related to AddToCart and SignIn or the model should include another «process link» that establishing where the navigation will continue after the process ends, such as by the CheckoutProcess. The process itself is defined in a separate model (see next section). Fig. 9 shows the navigation model after its first construction step. Note that associations which are not explicitly stereotyped are stereotyped associations of type «navigation link» (we omit them to avoid overloading). As example of a Amazon product line we only show the «navigation class» Book to keep the diagram simple as no modeling differences would be shown by including other product lines, such as classes DVD or CD. Although the notation for a bidirectional link with a line without arrows is not intuitive, we prefer to stick to the UML notation. The second step in the construction of the navigation model consists of the enhancement of the model by a set of access structures needed for the navigation. In a first step, this enhancement is partially automated, it consist in introducing indexes, guided-tours and queries. For each of these constructs UWE defines a stereotyped class «index», «query» and «guided tour». In Fig. 10 we use icons for indexes (e.g. OrderList) and queries (e.g. SearchProduct), which are defined by UWE within the UML extension mechanisms [Koch & Kraus 2001]. <<navigation class>> Homepage +Recommendations +YourAccount MainMenu +Search SignIn ? <<process link>> AccountInfo Book SearchProducts Recommendation <<process class>> SignIn +OrderView +ViewCart SelectedResults <<process link>> +PersonalInfo 1..* 0..1 OrderList 1..* <<navigation class>> <<navigation class>> <<navigation class>> <<navigation class>> Book Product ShoppingCart Customer <<process link>> 0..* <<process link>> <<navigation class>> <<process link>> Order 0..* CustomerOrders <<process class>> <<process class>> AddToCart Checkout ShoppingCartItems OrdeItems 0..* 0..* <<navigation class>> <<navigation class>> ShoppingCartItem OrderItem Fig. 10. UWE Navigation Model (with Access Elements) of the Checkout Process