Test II (Java Basic)

What is the output of running the following command for the given Java class from command prompt?

prompt>java ArgsNullCheck

public class ArgsNullCheck {

public static void main(String[ ] args){

System.out.println(args.length)

}

}


What will be the output of the following java class?

public class Main {

public static void main(String[] args) {

System.out.println("This is main. 1");

}

private static void main(String args) {

System.out.println("This is main. 2");

}

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

System.out.println("This is main. 3");

}

}


What is the output of running the following class?

public class StringComp {

public static void main(String[] args) {

String a = "unique";

String b = "unique";

System.out.println(a.equals(b));

System.out.println(a.hashCode()== b.hashCode());

}

}


What is the output of running the following Java class?

public class Main {

public static void main(String[] args) {

String a;

String b;

char[] arr = {'u', 'n', 'i', 'q', 'u', 'e', '\0'};

a = "unique";

b = new String(arr);

System.out.println(a.equals(b));

System.out.println(a.hashCode()== b.hashCode());

}

}


What is the output of running the Derived class

public class Super{

{

System.out.println("Super class block");

}

static {

System.out.println("Super class static block");

}

public Super(){

System.out.println("Super Constructor");

}

}

public class Derived extends Super{

{

System.out.println("Derived class block");

}

static {

System.out.println("Derived class static block");

}

public Derived(){

System.out.println("Derived Constructor");

}

public static void main(String[] args){

new Derived();

}

}


What replaces the /* some code here */ in the following code snippet so that the finally {} code block is not executed?

public class ExceptionHandling {

public static void main(String[] args) {

try {

throw new Exception("Kill the Main");

} catch (Exception ex) {

System.out.println("Ditch Finally");

/* some code here */

} finally{

System.out.println("You can't tell me nothing!!!");

}

}

}


What is result of compiling and running the following code?

import java.util.*;

class Vehicle {}

class Car extends Vehicle {}

class Bus extends Vehicle {}

class TestSamp {

public static void main(String [] args) {

ArrayList<Car> a = new ArrayList<Car>();

a.add(new Car());

ArrayList b = a;

ArrayList<Bus> c = (ArrayList<Bus>)b;

c.add(new Bus());

for (Object obj : b)

System.out.println(obj);

}

}


What will be the output of the following program?

public class LoopCase {

public static void main(String[] args) {

for (int i=0; i<5; i++){

switch (i){

case 0:

System.out.println("0");

++i;

break;

case -1:

System.out.println("-1");

break;

case 2:

System.out.println("2");

i++;

case 4:

System.out.println("4");

break;

}

}

}

}


What will be the output of the following program?

public class ThreadQ {

public static void main(String[] args) {

HelloThread hello = new HelloThread();

hello.start();

}

}

class MyThread implements Runnable{

@Override

public void run() {

System.out.println("My thread");

}

}

class HelloThread extends Thread{

public void start(){

System.out.println("Hello thread");

}

public void run(){

Thread thread = new Thread(new MyThread());

thread.start();

}

}


What is the result of compiling and running the following code?

enum AccountType {

SAVING, FIXED, CURRENT;

private AccountType() {

System.out.println("It is a account type");

}

}

class EnumOne {

public static void main(String[] args) {

System.out.println(AccountType.FIXED);

}

}















































































































































































Discussion
1 Follower
Test: 1

Your Facebook Friends on WizIQ