Zum Inhalt springen

Kurs:Informatik I/T2

Aus Wikiversity

T2 - Variables and primitive Types

[Bearbeiten]

1 Given the Java program Scope below: what is the value of attr1 after executing the following sequence?

method1();  ⊟  method1();  ⊟  method2();

public class Scope {

public static int attr1;
public static boolean attr2;
public static void method1() {
int number= 20;
attr1 = number;
}
public static void method2() {
attr1 = number;
}
static int number = 100;

}


120
140
100

2 Which of the following statements is correct?

123456 is a literal of type int
"c" is a literal of type character
true is a literal of type boolean
'\t' is a literal of type character
"false" is a literal of type boolean
3.14 is a literal of type double
3.14 is a literal of type float
1234 is a literal of type short

3 Which of the following Java declarations is syntactically correct?

boolean first_try_of_the_day;
public static void method() { boolean true; }
int tipp-log;
public class sillyputty { public static boolean silly; }
public class Empty() { }
public static void yahoo() { System.out.println("yahoo"); }

4 Given the following declarations, which of the following assignations is illegal?

int a1, a2;
boolean b;
double d1, d2;
char c;


d2 = d1;
d1= a1;
a1 = b;
a1 = a2;
b = c;

5 Which statements are true of higher level languages?

They have a strict type system.
Their syntax is not quite so strict as with lower level languages.
They are easier compiled than lower level languages.
They are built for readability.
They allow for user defined data types.
They are built according to the von Neumann architecture.