- 讲师:刘萍萍 / 谢楠
- 课时:160h
- 价格 4580 元
特色双名师解密新课程高频考点,送国家电网教材讲义,助力一次通关
配套通关班送国网在线题库一套
answer 1)
1) the code will compile and run, printing out the words "my func"
a class that contains an abstract method must be declared abstract itself, but may contain non abstract methods.
answer 2)
4) the code will compile but will complain at run time that main is not correctly defined
in this example the parameter is a string not a string array as needed for the correct main method
answer 3)
1) public
4) transient
the keyword transient is easy to forget as is not frequently used. although a method may be considered to be friendly like in c++ it is not a java keyword.
answer 4)
2) the compiler will complain that the base class is not declared as abstract.
if a class contains abstract methods it must itself be declared as abstract
answer 5)
1) to get to access hardware that java does not know about
answer 6)
4) success in compilation and output of "amethod" at run time.
a final method cannot be ovverriden in a sub class, but apart from that it does not cause any other restrictions.
answer 7)
4) compilation and execution without error
it would cause a run time error if you had a call to amethod though.
|||answer 8)
1)compile time error: base cannot be private
a top leve (non nested) class cannot be private.
answer 9)
4) p1 compiles cleanly but p2 has an error at compile time
the package statement in p1.java is the equivalent of placing the file in a different directory to the file p2.java and thus when the compiler tries to compile p2 an error occurs indicating that superclass p1 cannot be found.
answer 10)
2) an error at run time
this code will compile, but at run-time you will get an arrayindexoutofbounds exception. this becuase counting in java starts from 0 and so the 5th element of this array would be i.
remember that arrays will always be initialized to default values wherever they are created.
answer 11)
2)myarray.length;
the string class has a length() method to return the number of characters. i have sometimes become confused between the two.
answer 12)
3) a frame with one large button marked four in the centre
the default layout manager for a frame is the borderlayout manager. this layout manager defaults to placing components in the centre if no constraint is passed with the call to the add method.
answer 13)
4) do nothing, the flowlayout will position the component
answer 14)
1) use the setlayout method
|||answer 15)
1) ipadx
3) insets
answer 16)
2) the buttons will run from left to right along the top of the frame
the call to the setlayout(new flowlayout()) resets the layout manager for the entire frame and so the buttons end up at the top rather than the bottom.
answer 17)
2) it is a field of the gridbagconstraints class for controlling component placement
answer 18)
4) clean compile but no output at runtime
answer 19)
2) false
you can re-use the same instance of the gridbagconstraints when added successive components.
answer 20)
4) an interface that ensures that implementing classes cannot contain duplicates
answer 21)
2) the add method returns false if you attempt to add an element with a duplicate value
i find it a surprise that you do not get an exception.
answer 22)
1) the program exits via a call to exit(0);
3) a call to the stop method of the thread class
|||
answer 23)
4) the class can only access final variables
answer 24)
option 3 looks plausible but there is no guarantee that the thread that grabs the cpu time will be of a higher priority. it will depend on the threading algorithm of the java virtual machine and the underlying operating system
answer 25)
answer 26)
1) none of these options
because of the lack of a break statement after the break 10; statement the actual output will be
"ten" followed by "twenty"
answer 27)
4) system.gc();
answer 28)
1) compilation succeeds and at run time an output of 0 and false
answer 29)
1) compile time error
you will get an error saying something like "cant make a static reference to a non static variable". note that the main method is static. even if main was not static the array argv is local to the main method and would thus not be visible within amethod.
answer 30)
3) output of "not equal"
despite the actual character strings matching, using the == operator will simply compare memory location. because the one string was created with the new operator it will be in a different location in memory to the other string.
|||answer 31)
4) compile and run with output of "pausing" and "continuing" after a key is hit
an overriden method in a sub class must not throw exceptions not thrown in the base class. in the case of the method amethod it throws no exceptions and will thus compile without complain. there is no reason that a constructor cannot be protected.
answer 32)
4) compile time error because of the line creating the instance of inner
inner i = new outer().new inner();
then the code would compile and run producing the output "inner"
answer 33)
1) error at compile time
if you implement an interface you must create bodies for all methods in that interface. this code will produce an error saying that mywc must be declared abstract because it does not define all of the methods in windowlistener. option 4 is nonsense as comments can appear anywhere. option 3 suggesting that it might compile but not produce output is ment to mislead on the basis that what looks like a constructor is actually an ordinary method as it has a return type.
answer 34)
4) compile time error
an error will be caused by attempting to define an integer as static within a method. the lifetime of a field within a method is the duration of the running of the method. a static field exists once only for the class. an approach like this does work with visual basic.
answer 35)
4)int z = 015;
the letters c and s do not exist as literal indicators and a string must be enclosed with double quotes, not single as in this case.
answer 36)
1)double
note the upper case s on switch means it is not a keyword and the word then is part of visual basic but not java. also, instanceof looks like a method but is actually a keyword,
|||answer 37)
4) -3.0
answer 38)
3) one
command line parameters start from 0 and from the first parameter after the name of the compile (normally java)
answer 39)
4) the set is designed for unique elements.
collection is an interface, not a class. the collection interface includes a method called iterator. this returns an instance of the iterator class which has some similarities with enumerators.
answer 40)
2) if multiple listeners are added to a component the events will be processed for all but with no guarantee in the order
it ought to be fairly intuitive that a component ought to be able to have multiple listeners. after all, a text field might want to respond to both the mouse and keyboard
answer 41)
1) b=m;
you can assign up the inheritance tree from a child to a parent but not the other way without an explicit casting. a boolean can only ever be assigned a boolean value.
answer 42)
2) you can obtain a mutually exclusive lock on any object
4) thread scheduling algorithms are platform dependent
yes that says dependent and not independent.
|||answer 43)
2) ask for a re-design of the hierarchy with changing the operating system to a field rather than class type
this question is about the requirement to understand the difference between the "is-a" and the "has-a" relationship. where a class is inherited you have to ask if it represents the "is-a" relationship. as the difference between the root and the two children are the operating system you need to ask are linux and windows types of computers.the answer is no, they are both types of operating systems. so option two represents the best of the options. you might consider having operating system as an interface instead but that is another story.
of course there are as many ways to design an object hierarchy as ways to pronounce bjarne strousjoup, but this is the sort of answer that sun will proabably be looking for in the exam. questions have been asked in discussion forums if this type of question really comes up in the exam. i think this is because some other mock exams do not contain any questions like this. i assure you that this type of question can come up in the exam. these types of question are testing your understanding of the difference between the is-a and has-a relationship in class design.
answer 44)
1) an inner class may be defined as static
a static inner class is also sometimes known as a top level nested class. there is some debate if such a class should be called an inner class. i tend to think it should be on the basis that it is created inside the opening braces of another class. how could a programmer provide a constructor for an anonymous class?. remember a constructor is a method with no return type and the same name as the class. inner classes may be defined as private
answer 45
4) compilation and output of "not equal! 10"
the output will be "not equal 10". this illustrates that the output +=10 calculation was never performed because processing stopped after the first operand was evaluated to be false. if you change the value of b1 to true processing occurs as you would expect and the output is "we are equal 20";.
answer 46)
2)j= i责编:罗莉
上一篇:格林模拟试题一参考答案
下一篇:格林模拟试题三(下)(1)
课程专业名称 |
讲师 |
课时 |
查看课程 |
---|
课程专业名称 |
讲师 |
课时 |
查看课程 |
---|
点击加载更多评论>>