Java Reference
In-Depth Information
13 System.out.print(o + " " );
14 System.out.println();
15 }
16 }
11.21
Show the output of the following code:
public class Test {
public static void main(String[] args) {
new Person().printPerson();
new Student().printPerson();
public class Test {
public static void main(String[] args) {
new Person().printPerson();
new Student().printPerson();
}
}
}
}
class Student extends Person {
@Override
public String getInfo() {
return "Student" ;
class Student extends Person {
private String getInfo() {
return "Student" ;
}
}
}
}
class Person {
private String getInfo() {
return "Person" ;
class Person {
public String getInfo() {
return "Person" ;
}
}
public void printPerson() {
System.out.println(getInfo());
}
}
public void printPerson() {
System.out.println(getInfo());
}
}
(a)
(b)
11.22
Show the output of following program:
1 public class Test {
2 public static void main(String[] args) {
3 A a = new A( 3 );
4 }
5 }
6
7 class A extends B {
8 public A( int t) {
9 System.out.println( "A's constructor is invoked" );
10 }
11 }
12
13 class B {
14 public B() {
15 System.out.println( "B's constructor is invoked" );
16 }
17 }
Is the no-arg constructor of Object invoked when new A(3) is invoked?
11.23
Show the output of following program:
public class Test {
public static void main(String[] args) {
new A();
new B();
}
}
 
Search WWH ::




Custom Search