First line: System.out.println("Result: " + 2 + 3 + 5); String concatenation is produced.
Second line: System.out.println("Result: " + 2 + 3 * 5); 3*5 is calculated to 15 and is appended to string 2. Result 215. The output is: Result: 235 Result: 215
Note #1: To produce an arithmetic result, the following code would have to be used: System.out.println("Result: " + (2 + 3 + 5)); System.out.println("Result: " + (2 + 1 * 5)); run: Result: 10 Result: 7
Note #2: If the code was as follows: System.out.println("Result: " + 2 + 3 + 5"); System.out.println("Result: " + 2 + 1 * 5"); The compilation would fail. There is an unclosed string literal, 5", on each line.
Question : You have been given following code
public class Student { public String name = ""; public int age = 0; public String major = "Undeclared"; public boolean fulltime = true;
public void display() { System.out.println("Name: " + name + " Major: " + major); }
public boolean isFullTime() { return fulltime; } }
public class TestStudent { public static void main(String[] args) { Student bob = new Student(); bob.name = "Bob"; bob.age = 18; bob.year = 1982; } }