About Question enthuware.ocajp.i.v7.2.1071 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
dragontbone
Posts: 2
Joined: Wed Apr 16, 2014 4:47 am
Contact:

About Question enthuware.ocajp.i.v7.2.1071 :

Post by dragontbone »

when i run this code, I get a compile time error on this line: System.out.println(b = c);
what am i doing wrong?


public class Primitive{

int a = 1;
int[] ia = new int[10];
int b = ia[a];
int c = b + a;
System.out.println(b = c);

public static void main(String [ ] args){

}

}

sasha32003
Posts: 12
Joined: Tue Aug 05, 2014 2:47 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1071 :

Post by sasha32003 »

dragontbone wrote:when i run this code, I get a compile time error on this line: System.out.println(b = c);
what am i doing wrong?


public class Primitive{

int a = 1;
int[] ia = new int[10];
int b = ia[a];
int c = b + a;
System.out.println(b = c);

public static void main(String [ ] args){

}

}

Hi. You cannot do System.out.println(); there. Has to be in a method or a constructor.
Your code should look something like this:

Code: Select all

public class Primitive{

	int a = 1;
	int[] ia = new int[10];
	int b = ia[a];
	int c = b + a;
        
        public Primitive(){
               System.out.println(b = c);
        }
	
        public static void main(String [  ] args){
		
	}

}

dragontbone
Posts: 2
Joined: Wed Apr 16, 2014 4:47 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1071 :

Post by dragontbone »

I see. thanks

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 34 guests