JavaQuizzes

Multiple Choice Question

Which of the following for statements are valid?

A.

for(;;){}

B.

for(int i;;){}

C.

for(int i;;i++){}

D.

for(int i=0;;i++){}

E.

int i = 0;
for(;;i++){}

F.

for(;true;){}

G.

for(int i=0;true;i++);

 

Descriptive Question

Find output:

public class MyClass {

  int id;

  public static void main(String[] args) throws Exception {

    MyClass mc = new MyClass();

    mc.id=10;

    System.out.println(mc.clone().id);

  }

}

 

Descriptive Question

Find output:

public class MyClass {

  int id;

  public static void main(String[] args) throws Exception {

    MyClass mc = new MyClass();

    mc.id=10;

    System.out.println(((MyClass)mc.clone()).id);

  }

}

 

Multiple Choice Question

Given interface Inter

interface Inter {
	
	void myMethod() {
	}
}

Which all implementations are valid?

A.

abstract class MyAbstract implements Inter{

    public abstract void myMethod();
}

B.

abstract class MyAbstract1 implements Inter{

    abstract void myMethod();
}

C.

abstract class MyAbstract2 implements Inter{

    void myMethod();
}

D.

abstract class MyAbstract3 implements Inter{

    void myMethod() {}
}

E.

abstract class MyAbstract4 implements Inter{

    public void myMethod() {}
}

F.

abstract class MyAbstract5 implements Inter{

    public abstract void myMethod() {}
}

G.

abstract class MyAbstract implements Inter{

    @Override
    public abstract void myMethod();
}

 

Multiple Choice Question

Which of the followinf interface declarations are valid.

A.

interface Inter1 {
    
    void myMethod();
    
    class inner {}
}

B.

interface Inter2 {
    
    void myMethod();
    
    static class inner {}
}

C.

interface Inter3 {
    
    void myMethod();
    
    public static class inner {}
}

D.

interface Inter4 {
    
    void myMethod();
    
    public static final class inner {}
}

E.

interface Inter5 {
    
    void myMethod();
    
    public static abstract class inner {}
}

F.

interface Inter6 {
    
    void myMethod();
    
    protected static abstract class inner {}
}

Multiple Choice Question

Which statement regarding the following code is correct?

class A{

public int i = 10;

private int j = 20;

}

class B extends A{

private int i = 30; //1

public int k = 40;

}

class C extends B{

}

public class TestClass{

public static void main(String args[]){

C c = new C();

System.out.println(c.i); //2

System.out.println(c.j); //3

System.out.println(c.k);

} }

 

Select 1 option

A. It will print 10 and 40 if //3 is commented.

B. It will print 40 if //2 and //3 are commented.

C. It will not compile because of //1.

D. It will compile if //2 is commented.

E. None of these.

Multiple Choice Question

Given:

interface I {
}

class A implements I {
	
	public void m(){
		
	}
}

abstract class B extends A { //line 1

	public abstract void m(); //line 2
}

class C extends B { //line 3
	
}

 

Select 1 option

A. Class will compile successfully

B. Compilation will fail at line marked as line 1.

C. Compilation will fail at line marked as line 2.

D. Compilation will fail at line marked as line 3.

Descriptive Question

Predict output:

public class PrefixPostfixCheck {

	public static void main(String[] args) {
		int i=5;
		i=i++;
		System.out.println(i);
	}
}

 

Descriptive Question

Predict output:

public class ExceptionCheck {

	static int i = 10;

	public static void main(String[] argds) {
		System.out.println(myMethod());
		System.out.println(i);
	}

	public static int myMethod() {
		try {
			throw new RuntimeException();
		} finally {
			i = 12;
		}
	}
}

 

Descriptive Question

Find the result:

public class NullOverloadCheck {

	static void myMethod(Object o)
	{
		System.out.println("Object");
	}
	
	static void myMethod(Integer i){
		
		System.out.println("Integer");
	}
	
	public static void main(String[] args)
	{
		myMethod(null);
	}
	
}

 

Pages

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!