- 相关推荐
浙大网新中研软件开发工程师笔试题
选择题
1: Consider the class hierarchy shown below:
——————————————————————–
class FourWheeler implements DrivingUtilities
class Car extends FourWheeler
class Truck extends FourWheeler
class Bus extends FourWheeler
class Crane extends FourWheeler
———————————————————————-
Consider the following code below:
1.DrivingUtilities du;
2.FourWheeler fw;
3.Truck myTruck = new Truck();
4.du = (DrivingUtilities)myTruck;
5.fw = new Crane();
6.fw = du;
Which of the statements below are true?
Choices:
A.Line 4 will not compile because an interface cannot refer to an object.
B.The code will compile and run.
C.The code will not compile without an explicit cast at line 6, because going down the hierarchy without casting is not allowed.
D.The code will compile if we put an explicit cast at line 6 but will throw an exception at runtime.
2:A class design requires that a member variable should be accessible only by same package, which modifer word should be used?
A.protected
B.public
C.no modifer
D.private
3:
What is the result when you compile and run the following code?
public class ThrowsDemo
{
static void throwMethod()
{
System.out.println(“Inside throwMethod.”);
throw new IllegalAccessException(“demo”);
}
public static void main(String args[])
{
try
{
throwMethod();
}
catch (IllegalAccessException e)
{
System.out.println(“Caught ” + e);
}
}
}
Choices:
What is the result when you compile and run the following code?
public class ThrowsDemo
{
static void throwMethod()
{
System.out.println(“Inside throwMethod.”);
throw new IllegalAccessException(“demo”);
}
public static void main(String args[])
{
try
{
throwMethod();
}
catch (IllegalAccessException e)
{
System.out.println(“Caught ” + e);
}
}
}
Choices:
A.Compilation error
B.Runtime error
C.Compile successfully, nothing is printed.
D.Inside throwMethod. followed by caught:java.lang.IllegalAccessExcption: demo
4:
In the following code, which is the earliest statement, where the object originally held in e, may be garbage collected:
1.public class Test {
2. public static void main (String args []) {
3. Employee e = new Employee(“Bob”, 48);
4. e.calculatePay();
5. System.out.println(e.printDetails());
6. e = null;
7. e = new Employee(“Denise”, 36);
8. e.calculatePay();
9. System.out.println(e.printDetails());
10. }
11.}
Only One:
In the following code, which is the earliest statement, where the object originally held in e, may be garbage collected:
1.public class Test {
2. public static void main (String args []) {
3. Employee e = new Employee(“Bob”, 48);
4. e.calculatePay();
5. System.out.println(e.printDetails());
6. e = null;
7. e = new Employee(“Denise”, 36);
8. e.calculatePay();
9. System.out.println(e.printDetails());
10. }
11.}
Only One:
A.Line 10
B.Line 11
C.Line 7
D.Line 8
5:
What will be the result of executing the following code?
public static void main(String args[])
{
char digit = ‘a’;
for (int i = 0; i < 10; i++)
{
switch (digit)
{
case ‘x’ :
{
int j = 0;
System.out.println(j);
}
default :
{
int j = 100;
System.out.println(j);
}
}
}
int i = j;
System.out.println(i);
}
Choices:
What will be the result of executing the following code?
public static void main(String args[])
{
char digit = ‘a’;
for (int i = 0; i < 10; i++)
{
switch (digit)
{
case ‘x’ :
{
int j = 0;
System.out.println(j);
}
default :
{
int j = 100;
System.out.println(j);
}
}
}
int i = j;
System.out.println(i);
}
Choices:
A.100 will be printed 11 times.
B.The code will not compile because the variable i cannot be declared twice within the main() method.
C.The code will not compile because the variable j cannot be declared twice within the switch statement.
D.None of these.
【浙大网新中研软件开发工程师笔试题】相关文章:
一套软件开发工程师笔试题09-30
笔美国国家仪器试题目09-23
中粮上海笔经08-08
银行软件开发笔试题07-25
腾讯软件开发类笔试题07-28
中金CICC笔试题10-24
中鼎财富(北京)软件开发有限公司 操盘分析师笔试题10-12
机械工程师笔试题07-17
中粮集团笔试题分享07-08
某公司Java工程师笔试题09-20