Which codes are wrong A private int x y B int a Systemoutpr

Which codes are wrong?

A. private int x, y;

B. int a = System.out.println(11);

C. public class TestOne

{ public void mOne( ) { }

public int mTwo(int someInt) {return someInt;}

public void mThree ( ) {mOne(1004);}

}

D. public class TestTwo( ){ }

E. int choice = 1;
switch(choice)
{
   case 1:System.out.println(choice);break;
   default: System.out.println(-1);break;
}

F. if(true){ } <else{ }>

G. int a = 3;
do{System.out.println(“wrong”); a++}while(a < 10);

H. for(int 1 = i; i < 9; i++){ }

I. public class T1

{

private int a = 7;

public void m1( ){ }

public int m2 ( ){return 110;}

}

public class T10

{

private T1 t1 = new T1( );

}

J. public class T1

{

public void m1( ) { }

public int m2 (int userInput)

{return user1nput;}

}

public class T10

{

private T1 t1 = new T1( );

public int m3 ( )

{return t1.m2(1004); }

}

Solution

B. int a = System.out.println(11);

It is a wrong code as System.out.println() function has a return type void but we are assigning it to int which is an error.

C. public class TestOne

{ public void mOne( ) { }

public int mTwo(int someInt) {return someInt;}

public void mThree ( ) {mOne(1004);}

}

In function mThree() we are calling mOne with integer parameter but there is no function with a given signature hence it will result in errorneous code.

F. if(true){ } <else{ }>

is a wrong code as JAVA syntax does not allow < > for else block.Below is the correct code.

if(true){ }

else{ }

H. for(int 1 = i; i < 9; i++){ }

is a wrong code. it should be i = 1 not 1 = i

I.

public class T1

{

private int a = 7;

public void m1( ){ }

public int m2 ( ){return 110;}

}

public class T10

{

private T1 t1 = new T1( );

}

You cannot define two classes that too public in single java file hence if this code is part of single java file than it will result in error.

If these are present in two different java files say T1.java and T10.java then it should not be a problem.

J.

public class T1

{

public void m1( ) { }

public int m2 (int userInput)

{return user1nput;}

}

public class T10

{

private T1 t1 = new T1( );

public int m3 ( )

{return t1.m2(1004); }

}

Same reason as I

Which codes are wrong? A. private int x, y; B. int a = System.out.println(11); C. public class TestOne { public void mOne( ) { } public int mTwo(int someInt) {r
Which codes are wrong? A. private int x, y; B. int a = System.out.println(11); C. public class TestOne { public void mOne( ) { } public int mTwo(int someInt) {r
Which codes are wrong? A. private int x, y; B. int a = System.out.println(11); C. public class TestOne { public void mOne( ) { } public int mTwo(int someInt) {r

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site