Title: Test01
Course: Advanced Java Programming (APT TEMPLATE)

Test for Encapsulation competency.

Q: What output is produced by the following program code?

public class Ap078{
public static void main(String args[]){
new Worker().doArrays();
}//end main()
}//end class definition

class Worker{
public void doArrays(){
int[] A = new int[1];
double[] B = new double[1];
boolean[] C = new boolean[1];
int[] D = new int[0];

System.out.println(A[0] + " " +
B[0] + " " +
C[0] + " " +
D.length);

}//end doArrays()
}// end class
- Compiler Error
- Runtime Error
- 0 0.0 false 0
- None of the above
A: 0 0.0 false 0

Q: What output is produced by the following program code?

public class Ap077{
public static void main(String args[]){
new Worker().doArrays();
}//end main()
}//end class definition

class Worker{
public void doArrays(){
Subclass[] A = new Subclass[2];
A[0] = new Subclass(1);
A[1] = new Subclass(2);

Object X = A;
Superclass B = A;
Subclass[] C = (Subclass[])B;
Subclass[] Y = (Subclass[])X;
System.out.println(
C[0] + " " + Y[1]);
}//end doArrays()
}// end class

class Superclass{
private int data;
public Superclass(int data){
this.data = data;
}//end constructor

public int getData(){
return data;
}//end getData()

public String toString(){
return "" + data;
}//end toString()
}//end class SuperClass

class Subclass extends Superclass{
public Subclass(int data){
super(data);
}//end constructor
}//end class Subclass
- Compiler Error
- Runtime Error
- 1 2
- None of the above
A: Compiler Error

Q: What output is produced by the following program code?

public class Ap076{
public static void main(String args[]){
new Worker().doArrays();
}//end main()
}//end class definition

class Worker{
public void doArrays(){
int[] A[];
A = new int[2][3];

for(int i=0; i<A.length;i++){
for(int j=0;j<A[0].length;j++){
A[i][j] = i*j;
}//end inner loop
}//end outer loop

for(int i=0; i<A.length;i++){
for(int j=0;j<A[0].length;j++){
System.out.print(
A[i][j] + " ");
}//end inner loop
System.out.println();
}//end outer loop

}//end doArrays()
}// end class
- Compiler Error
- Runtime Error
- 0 0 0
0 1 2
- None of the above
A: 0 0 0
0 1 2

Q: What output is produced by the following program code?

public class Ap087{
public static void main(String args[]){
new Worker().doOverLoad();
}//end main()
}//end class definition

class Worker{
public void doOverLoad(){
SubC a = new SubC();
SuperC b = new SubC();

SubC obj = new SubC();
obj.overLoadMthd(a);
obj.overLoadMthd(b);

System.out.println();
}//end doOverLoad()

}// end class

class SuperC{
public void overLoadMthd(SuperC x){
System.out.print("SuperC ");
}//end overLoadMthd
}//end SuperC

class SubC extends SuperC{
public void overLoadMthd(SubC x){
System.out.print("SubC ");
}//end overLoadMthd
}//end class SubC
- Compiler Error
- Runtime Error
- SubC SuperC
- None of the above
A: SubC SuperC

Q: What output is produced by the following program code?

public class Ap085{
public static void main(String args[]){
new Worker().doOverLoad();
}//end main()
}//end class definition

class Worker{
public void doOverLoad(){
Test a = new Test();
DumIntfc b = new Test();
overLoadMthd(a);
overLoadMthd(b);
System.out.println();
}//end doOverLoad()

public void overLoadMthd(Test x){
System.out.print("Test ");
}//end overLoadMthd

public void overLoadMthd(DumIntfc x){
System.out.print("DumIntfc ");
}//end overLoadMthd
}// end class

interface DumIntfc{
}//end DumIntfc

class Test implements DumIntfc{
}//end class Test
- Compiler Error
- Runtime Error
- Test DumIntfc
- None of the above
A: Test DumIntfc

Q: What output is produced by the following program code?

public class Ap081{
public static void main(String args[]){
new Worker().doOverLoad();
}//end main()
}//end class definition

class Worker{
public void doOverLoad(){
double w = 3.2;
double x = 4.2;

int y = square(w);
double z = square(x);

System.out.println(y + " " + z);
}//end doOverLoad()

public int square(double y){
return (int)(y*y);
}//end square()

public double square(double y){
return y*y;
}//end square()

}// end class
- Compiler Error
- Runtime Error
- 10 17.64
- None of the above
A: Compiler Error

Q: What output is produced by the following program code?

public class Ap099{
public static void main(String args[]){
new Worker().makeObj();
}//end main()
}//end class definition

class Worker{
public void makeObj(){
NewClass obj = new NewClass(5);
obj.x = 10;
System.out.println(obj.x);
}//end makeObj()
}// end class

class NewClass{
private int x = 2;

public NewClass(){
}//end constructor

public NewClass(int x){
this.x = x;
}//end constructor

public void setX(int x){
this.x = x;
}//end setX()

public int getX(){
return x;
}//end getX()
}//end NewClass
- Compiler Error
- Runtime Error
- 2
- 5
- 10
- None of the above
A: Compiler Error

Q: What output is produced by the following program code?

public class Ap098{
public static void main(String args[]){
new Worker().makeObj();
}//end main()
}//end class definition

class Worker{
public void makeObj(){

NewClass obj = new NewClass();
obj.setX(10);
System.out.println(obj.getX());

}//end makeObj()
}// end class

class NewClass{
private int y;

public void setX(int y){
this.y = y;
}//end setX()

public int getX(){
return y;
}//end getX()
}//end NewClass
- Compiler Error
- Runtime Error
- 10
- None of the above
A: 10

Q: What output is produced by the following program code?

public class Ap097{
public static void main(String args[]){
new Worker().makeObj();
}//end main()
}//end class definition

class Worker{
public void makeObj(){
NewClass obj = new NewClass(5);
System.out.println(obj.getX());
}//end makeObj()
}// end class

class NewClass{
private int x = 2;

public NewClass(){
}//end constructor

public NewClass(int x){
this.x = x;
}//end constructor

public int getX(){
return x;
}//end getX()
}//end NewClass
- Compiler Error
- Runtime Error
- 2
- 5
- None of the above
A: 5

Q: What output is produced by the following program code?

public class Ap094{
public static void main(String args[]){
new Worker().makeObj();
}//end main()
}//end class definition

class Worker{
public void makeObj(){
Subclass obj = new Subclass();
System.out.println(obj);
}//end makeObj()
}// end class

class Superclass{
private int x;

public Superclass(int x){
this.x = x;
}//end constructor

public String toString(){
return "Object containing " + x;
}//end toString()

public void setX(int x){
this.x = x;
}//end setX()
}//end Superclass

class Subclass extends Superclass{
public Subclass(){
setX(2);
}//end noarg constructor
}//end Subclass
- Compiler Error
- Runtime Error
- Object containing 2
- None of the above
A: Compiler Error

Q: What output is produced by the following code?

public class Ap101{
public static void main(
String args[]){
new Worker().makeObj();
}//end main()
}//end class definition

class Worker{
public void makeObj(){
Subclass obj = new Subclass();
System.out.println(obj.getX() +
", " + obj.getY());
}//end makeObj()
}// end class

class Superclass{
private int x = 1;

public Superclass(){
x = 5;
}//end constructor

public Superclass(int x){
this.x = x;
}//end constructor

public int getX(){
return x;
}//end getX()
}//end Superclass

class Subclass extends Superclass{
private int y = 2;

public Subclass(){
super(20);
y = 10;
}//end constructor

public int getY(){
return y;
}//end getY()
}//end Subclass
- Compiler Error
- Runtime Error
- 1, 2
- 5, 2
- 5, 10
- 20, 10
- None of the above
A: 20, 10

Q: What output is produced by the following code?

public class Ap102{
public static void main(
String args[]){
new Worker().finalStuff();
}//end main()
}//end class definition

class Worker{
public void finalStuff(){
final int x = 5;
x = 10;
System.out.println(x);
}//end finalStuff()
}// end class
- Compiler Error
- Runtime Error
- 5
- None of the above
A: Compiler Error

Q: What output is produced by the following code?

public class Ap103{
public static void main(
String args[]){
new Worker().finalStuff();
}//end main()
}//end class definition

class Worker{
public void finalStuff(){
public final int x = 5;
System.out.println(x);
}//end finalStuff()
}// end class
- Compiler Error
- Runtime Error
- 5
- None of the above
A: Compiler Error

Q: What output is produced by the following code?

public class Ap107{
public static void main(
String args[]){
Worker.staticMethod();
}//end main()
}//end class Ap107

class Worker{
private int x = 5;
public static void staticMethod(){
System.out.println(x);
}//end staticMethod()

}// end class
- Compiler Error
- Runtime Error
- 5
- None of the above
A: Compiler Error

Q: What output is produced by the following code?

public class Ap110{
public static void main(
String args[]){
new Worker().doThis();
}//end main()
}//end class Ap110

class Worker{
private int data = 33;

public void doThis(){
new Helper().helpMe(this);
}//end area()

public String getData(){
return data;
}//end getData()
}// end class Worker

class Helper{
public void helpMe(Worker param){
System.out.println(
param.getData());
}//end helpMe()
}//end class Helper
- Compiler Error
- Runtime Error
- 33
- None of the above
A: Compiler Error