Composition is where one class contains an object from another class.
If class A is the base class and B is the derived class, A is also called the superclass and B is called the subclass.
Ans: If x is-a y makes sense, where x is an object of A and y is an object of B, then A inherits B.
Ans: If the object x of class A has-a y where y is an object of class B, then this is an example of composition.
Ans: true.
Ans: For two things (1) invoke a constructor from the base class and (2) invoke a method from the base class where that method is overridden in the derived class.
Ans: True the Object class is directly or indirectly the parent class of every Java class.
int a[ ][ ] = {{2,3,4},{3,4,5},{5,6,7}};
int i = 0, j = 1;
System.out.println(a[j][i]);
Ans: 3.
Ans:
public static void main(String[ ] args) throws FileNotFoundException
{
Scanner s = new Scanner(new FileReader("array.txt"));
int width = s.nextInt( );
int height = s.nextInt( );
int[ ][ ] array = new int[height][width];
for(int j = 0; j < height; j++)
for(int i = 0; i < height; i++)
array[j][i] = s.nextInt( );
for(int j = 0; j < height; j++)
{
for(int i = 0; i < height; i++)
System.out.printf("%5.2f", array[j][i]);
System.out.println( );
}
}
Trace1 Example:
+---+ +---+ +---+
a1| O------+ a2| O------+ b1| O------+
+---+ | +---+ | +---+ |
V V V
w h w h w h d
----+---- ----+---- ----+---+----
3 4 10 11 20 21 420
3 11 11 18 23 28 3
Output: 11x3
18x11
28x23x3