Question: b) ) Write Java code for inserting the following numbers 1, 2, 3, 4 into i) an Array, and ii) a ArrayList c) What is
b) ) Write Java code for inserting the following
numbers 1, 2, 3, 4 into i) an Array, and ii) a ArrayList
c) What is the output of the following program.
public class Test
{
public static void main(String args[])
{ StringBuffer sb = new StringBuffer("abcdef");
sb.replace(0, 3, "xyz");
System.out.println(sb);
sb = new StringBuffer("abcdef");
sb.replace(sb.indexOf("abc"), sb.indexOf("def"), "lmo");
System.out.println(sb); }
}
d)
public interface Once{
public void sayItOnce(); }
public interface Twice{
public void sayItTwice(); }
public class A implements Once {
public void one() {
System.out.println( "A.1" ); }
public void two(){
one();
System.out.println( "A.2" ); }
public void sayItOnce() {
System.out.println("Ill say this once"); }
}
public class B extends A implements Once, Twice
{
public void one( int x){
System.out.println( "B.1 " + x ); }
public void two() {
System.out.println( "B.2" ); }
public void sayItTwice() {
System.out.println("Ill say this twice "); }
}
public class C extends A
{
public void one() {
System.out.println( "C.1" ); }
}
If the following pieces of code were to appear in a control program that used the classes A,B and C what would be the outputs
i)
A a = new B();
a.two();
ii)
B b = new B();
b.one(4);
b.one();
iii)
Once r = new B();
r.sayItOnce();
iv)
Twice b = new Twice();
b.sayItTwice();
v)
C c = new A();
c.two();
vi)
A a = new B();
a.sayItTwice() ;
vii)
A a = new C();
a.two();
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
