class Tree {
void print () {System.out.println("Tree"); }
public static void main(String args[]) {
Tree[] a = new Tree[3];
a[0] new Tree();
a[1] new Banyan();
a[2] new Peepal();
for (int i=0; i<a.length; i++) {
((Tree) a[i]).print();
}
What will happen when you try to compile and run this program?
Answers
Answered by
0
Answer:
so the answer will be
Tree
Banyan
Peepal
Answered by
0
Answer:
we will get errors when we will try to compile and run this program.
Explanation:
- Tree[] a = new Tree[3]; this statement creates the array of Tree objects and there are 3 objects of type Tree.
- a[0] new Tree(); a[1] new Banyan(); a[2] new Peepal(); these three statements are not valid statements.
- There is no class named Banyan or Peepal; so we can't create & initialize their objects using constructor.
- There is a class called Tree and we can create & initialize actual Tree objects using constructor but the right syntax for that is a[0] =new Tree();
Similar questions
India Languages,
3 months ago
Computer Science,
6 months ago
Geography,
11 months ago
Political Science,
11 months ago