Skip to content

Commit

Permalink
Day 1 break 2
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHGR committed May 8, 2023
1 parent 37ca046 commit 8c2d420
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
63 changes: 62 additions & 1 deletion Questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,65 @@ D) void doStuff() {

E) void doStuff() {
var x = { 1, 2, 3 };
}
}

Q) Given:
var x = true ? "99" : 99;

What is the type of x?
A) none, it's fails to compile
B) int
C) String
D) Object
E) none of the above

Q) Given:

public static void main(String[] args) {
final StringBuilder sb = new StringBuilder("Hello");
sb.append(" world!");
System.out.println(sb);
}

What is the result?
A) Compilation fails
B) Hello
C) Hello world!
D) Exception at runtime

Q) Given:

String message = """Hello\
Java 17 World!""";
System.out.println(message + "XXX");

What is the result?
A) Compilation fails
B) Exception at runtime
C) Hello
Java 17 World!XXX
D) Hello Java 17 World!XXX
E) Hello Java 17 World!
XXX

Q) Given:
String message = """
Hello
Java 17 World!""";
System.out.println(message + "XXX");

What is the result?
A)
Hello
Java 17 World!XXX
B)
Hello
Java 17 World!XXX
C)
Hello
Java 17 World!
XXX
D)
Hello
Java 17 World!
XXX
18 changes: 18 additions & 0 deletions src/main/java/textblock/Ex1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package textblock;

public class Ex1 {
public static void main(String[] args) {
String message = """
Hello\
Java 17 World!""";
System.out.println("XXX" + message + "XXX");

System.out.println("------------");
String message2 = """
""\"""\"""Hello", he said
Java 17 World!
""";
System.out.println(message2 + "XXX");

}
}
14 changes: 14 additions & 0 deletions src/main/java/usingvar/Ex1.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ public static void main(String[] args) throws Throwable {
// try (FileReader in = new FileReader("")) {
// } catch (var ex) { }


// nope, can't change base type during autoboxing
// Long i = 2_000_000_000;

var x = true ? "99" : 99;

// Integer in = null; // also for String :)
// in.compareTo... and others

// int goto;
// var var = "var";
int var = 99;
}

// void doStuff() {
Expand All @@ -46,3 +58,5 @@ public static void main(String[] args) throws Throwable {
// showStuff(new String[]{"a", "b"});
// }
}

//class var {}

0 comments on commit 8c2d420

Please sign in to comment.