Which three statements are true?

  1. The default constructor

Loading

Practice Objects and Collections –

Which three statements are true?

  1. The default constructor initialises method variables.
  2. The default constructor has the same access as its class.
  3. The default constructor invokes the no-arg constructor of the superclass.
  4. If a class lacks a no-arg constructor, the compiler always creates a default constructor.
  5. The compiler creates a default constructor only when there are no other constructors for the class.

What will be the output of the program?


			  		

Loading

Practice Threads –

What will be the output of the program?

public class Test107 implements Runnable  {     
private int x;
private int y;
public static void main(String args[]) {
Test107 that = new Test107();
(new Thread(that)).start();
(new Thread(that)).start();
}
public synchronized void run() {
for(int i = 0; i < 10; i++) {
x++;
y++;
System.out.println("x = " + x + ", y = " + y); /* Line 17 */
}
}
}

 

/* Missing Statement ? */ 
publ

Loading

Practice Package –

/* Missing Statement ? */ 
public class foo {
public static void main(String[]args)throws Exception {
java.io.PrintWriter out = new java.io.PrintWriter();
new java.io.OutputStreamWriter(System.out,true);
out.println("Hello");
}
}

What line of code should replace the missing statement to make this program compile?

package testpkg.p1; 
public cla

Loading

Practice Package –

package testpkg.p1; 
public class ParentUtil {
public int x = 420;
protected int doStuff() {
return x;
}
}
package testpkg.p2;
import testpkg.p1.ParentUtil;
public class ChildUtil extends ParentUtil {
public static void main(String [] args) {
new ChildUtil().callStuff();
}
void callStuff() {
System.out.print("this " + this.doStuff() ); /* Line 18 */
ParentUtil p = new ParentUtil();
System.out.print(" parent " + p.doStuff() ); /* Line 20 */
}
}

which statement is true?

What will be the output of the program?


			  		

Loading

Practice Inheritance –

What will be the output of the program?

import java.util.*; 
public class NewTreeSet2 extends NewTreeSet { //line 2
public static void main(String [] args) {
NewTreeSet2 t = new NewTreeSet2();
t.count();
}
}
protected class NewTreeSet { //line 8
void count() {
for (int x = 0; x < 7; x++,x++ ) {
System.out.print(" " + x);
}
}
}

 

What will be the output of the program?


			  		

Loading

Practice Inheritance –

What will be the output of the program?

class Base {      
Base() {
System.out.print("Base");
}
}
public class Alpha extends Base {
public static void main(String[] args) {
new Alpha(); /* Line 12 */
new Base(); /* Line 13 */
}
}

 

What will be the output of the program?


			  		

Loading

Practice Inheritance –

What will be the output of the program?

class A {     
final public int GetResult(int a, int b) {
return 0;
}
}
class B extends A {
public int GetResult(int a, int b) {
return 1;
}
}
public class Test {
public static void main(String args[]) {
B b = new B();
System.out.println("x = " + b.GetResult(0, 1));
}
}

 

What is the output of the following code ?


			  		

Loading

Practice Inheritance –

What is the output of the following code ?

class A {
public int i;
protected int j;
}

class B extends A {
int j;
void display() {
super.j = 3;
System.out.println(i + " " + j);
}
}

class Output {
public static void main(String args[]) {
B obj = new B();
obj.i = 1;
obj.j = 2;
obj.display();
}
}

What is the output of the following program ?


			  		

Loading

Practice Inheritance –

What is the output of the following program ?


class A {
int i;
void display() {
System.out.println(i);
}
}
class B extends A {
int j;
void display() {
System.out.println(j);
}
}
class inheritance_demo {
public static void main(String args[]){
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}

class Boo {     
Boo(String s

Loading

Practice Inner Classes –

class Boo {     
Boo(String s) {
}
Boo() {
}
}
class Bar extends Boo {
Bar() {
}
Bar(String s) {
super(s);
}
void zoo() {
// insert code here
}
}

which one create an anonymous inner class from within class Bar?

Which is true about an anonymous inner class?

Loading

Practice Inner Classes –

Which is true about an anonymous inner class?

What will be the output of the program?


			  		

Loading

Practice Inner Classes –

What will be the output of the program?

public abstract class AbstractTest  {    
public int getNum() {
return 45;
}
public abstract class Bar {
public int getNum() {
return 38;
}
}
public static void main (String [] args) {
AbstractTest t = new AbstractTest() {
public int getNum() {
return 22;
};
AbstractTest.Bar f = t.new Bar() {
public int getNum() {
return 57;
}
};
System.out.println(f.getNum() + " " + t.getNum());
}
}

 

What will be the output of the program?


			  		

Loading

Practice Inner Classes –

What will be the output of the program?

public class TestObj {     
public static void main (String [] args) {
Object o = new Object() /* Line 5 */ {
public boolean equals(Object obj) {
return true;
}
} /* Line 11 */
System.out.println(o.equals("Fred"));
}
}