JAVA QUIZ 13

10
Created on By Sirjana GhimireAcharya

JAVA QUIZ 13

1 / 10

1.Output of following Java program?

public class Test{

public static void main(String[] args){

int i = 0;
for(; i < 10; i++){
break;
}
System.out.println(i);
}

}

2 / 10

2. What will happen when you compile and run the following code?

public class Test{

public static void main(String[] args){
int i = 0;
for(i = 100; i < = 0; i -= 10 ){
System.out.print(i + ", ");
}
}
}

3 / 10

3. What will happen when you compile and run the following code?

public class Test{

public static void main(String[] args){
for(char c = 'a' ; c < 'd'; c++){
System.out.print(c);
}
}
}

4 / 10

4. What will happen when you compile and run the following code?

public class Test{

public static void main(String[] args){
for(int i = 65; i < 68 ; i++){
System.out.print((char)i);
}
}
}

5 / 10

5. What will happen when you compile and run the following code?

class One{
int i = 1;
public int getInt(){
return i;
}
}

class Two extends One{
int i = 2;
public int getInt(){
return i;
}
}
public class Test{
public static void main(String[] args) {
One one = new One();
Two two = (Two)one;
System.out.println( two.getInt() );
}
}

6 / 10

6. What will happen when you compile and run the following code?

class One{
public static void print(int i){
System.out.println("Parent");
}
}

class Two extends One{
public static void print(byte b){
System.out.println("Child");
}
}

public class Test{

public static void main(String args[]){
One one = new Two();
one.print(10);
}
}

7 / 10

7. What will happen when you compile and run the following code?

class One{

public One(int x){
System.out.print("int constructor");
}

public One(long l){
System.out.print("long constructor");
}
}

public class Test{

public static void main(String[] args){
long l = 20l;
One one = new One(l);
}
}

8 / 10

8. A private method defined in the parent class cannot be overridden by child class.

9 / 10

9. Will this code compile without error?

import java.io.FileNotFoundException;
import java.io.IOException;

class One{
public void someMethod() throws IOException{
throw new IOException();
}
}
class Two extends One{
public void someMethod() throws FileNotFoundException{
throw new FileNotFoundException();
}
}

10 / 10

10. Select all method declarations that successfully override the someMethod() defined in the class One?

class One{
public void someMethod(int i) throws Exception{
}
}

class Two extends One{
//method declaration here
{
}
}

Your score is

The average score is 47%

0%