last day (894 days later) » 

user142019
20:07
Oh this question is hilarious.
@MooingDuck sounds like BS
@rubenvb hmm, the spec has a note that refers to the values of "uninitialized automatic objects"...
@FredOverflow already checking my sources
user142019
11. Which statement is true?
A. Encapsulation protects methods, so they cannot be overriden.
B. With encapsulation you use getter methods to assign variables a value.
C. With encapsulation you can change specific methods without it having an impact on other's code.
D. You use encapsulation when you start using reference variables as instance variables.
@FredOverflow spec refers to these variables as "uninitialized". Interesting.
user142019
B is a joke.
20:09
@Zoidberg But it is the expected answer
@Zoidberg C is the best I gusess
user142019
@sehe no, it's C.
@sehe Since when do getters set a value? :)
user142019
13. Which statement is true?
D. An instance variable is a variable of an object.
@FredOverflow I read the intent. (a.k.a. I missed that)
20:09
@Zoidberg I would chose C as well, but only based on the stupidity of the other choices.
user142019
@FredOverflow That's what I did too. :)
@sehe i was this close -> <- to setting up vim coding environment, when this happened. Screenshots look yummy.
@Zoidberg Replace "specific methods" by "implementation details" an I'd feel better.
@ScottW Yegge is big on typing. steve-yegge.blogspot.nl/2008/09/… That is contradicting
user142019
17. Which statement is true?
B. An `ArrayList` has more functionality than an array.
user142019
20:11
Such a weird and ambiguous answer.
user142019
Define "functionality" and "more".
@Zoidberg It does have more functionality. Different, mostly
All of your quizzles are weird.
Well, Java arrays suck. You can ask them for their length, and that's practically it.
user142019
lol I just see this.
20:12
@Zoidberg could you maybe GTFO with your questions(sic) about java (sic!) exam (SIC!) from here?
user142019
Question 19 lists this code:
user142019
class C1 {
    void m1() {}
    void m2() {}
    @Overload
    void m3() {}
}
user142019
WTF @Overload.
@BartekBanachewicz He's is entertainer in residence, he gets a pass
@BartekBanachewicz I find them highly amusing, but I wouldn't mind another room.
20:12
@FredOverflow More importantly, it's not really open. For a while, they pretended that outsiders had say in Java's development (and Sun just had veto power). The pretense apparently wore on them, however, so outsiders can suggest things, but they don't pretend it's any more than "we might use your idea if we feel like it."
@Zoidberg Java 1.5 annotations
§8.5/11: If no initializer is specified for an object, the object is default-initialized; if no initialization is performed, an object with automatic or dynamic storage duration has indeterminate value.
Let that be the end of it.
user142019
@sehe there is no @Overload.
user142019
There is @Override. Which is meant in this case.
Oh fuck. Your memory is way too good
20:13
@FredOverflow aha: § 8.5/6 "To default initialize an object of type T means [snip classes/arrays] no initialization is performed. So it was default initialized and uninitialized.
@Zoidberg @Overload is clearly a typo, he probably meant @Overlord ;)
@Zoidberg Nah. @Overload makes sense too. SystemOverloadException
1 min ago, by rubenvb
§8.5/11: If no initializer is specified for an object, the object is default-initialized; if no initialization is performed, an object with automatic or dynamic storage duration has indeterminate value.
@FredOverflow Damn -- I was just starting to say "I want the @overlord annotation." but you beat me to it.
@Rapptz That doesn't really surprise me.
20:14
class Gossip {
    @Overheard
    void whisper() {}
}
user142019
23. Which statement about classes and common state and behaviour within an inheritance relation is true?
A. It's best to place this in subclasses.
B. It's best to place this in superclasses.
C. It's best to place this in all classes in the inheritance relationship.
D. It's best to place this in a separate class outside of the inheritance relationship.
user142019
There is no answer to this question. Depends too much on the context.
user142019
And define "best".
@Zoidberg And there should always be at least one "all of the above", or "none of the above" for every multiple choice question.
user142019
@sehe could you move? :P
20:15
@Zoidberg "Within an inheritance relation". D is out of the question
@Zoidberg move what?
user142019
@sehe the Java crap to the Java Sucks room.
room topic changed to Java Sucks: Everything in Java is an object, except for the things that aren't. [java]
@sehe not true, you can also compose classes.
@Zoidberg Ah I will.
in Lounge<C++>, 1 min ago, by Zoidberg
23. Which statement about classes and common state and behaviour within an inheritance relation is true?
A. It's best to place this in subclasses.
B. It's best to place this in superclasses.
C. It's best to place this in all classes in the inheritance relationship.
D. It's best to place this in a separate class outside of the inheritance relationship.
I would guess B.
user142019
20:17
@FredOverflow B is correct.
user142019
At least, I ticked B.
Then it's definitely correct :)
56 messages moved from Lounge<C++>
@Zoidberg B is undoubtedly what they wanted, anyway.
10 visitors? Whoa, this room is alive :) More alive than the real Java room? :)
20:19
What's up
user142019
26. Imagine you have to use a closed-source, but nicely written, OO library. You only have the `.class` files. However, the classes don't completely conform to your wishes. You actually want to change the classes. Which solution is best?
A. Decompile. [shortly translated from Dutch]
B. Rewrite everything and expose the same API. Get the API spec from Javadoc.
C. Extend the class and override the behaviour.
D. Make a new abstract class and make this the superclass of the class you want to modify.
user142019
A and C are both correct. :^)
user142019
(And C is fucked up with sealed classes, if Java has those.)
@Zoidberg Hey, don't spoil the fun!
None of the answers "Change the classes", is that translated correctly?
@Zoidberg Java has final classes which prohibit inheritance.
user142019
> Je wil daarom de class eigenlijk aanpassen.
20:21
@Zoidberg final or static
@Zoidberg He knows you!
user142019
> Because of that, you actually want to modify the class.
@sehe There are no top-level static classes in Java.
user142019
That's what the question says.
@Zoidberg D is more of a challenge though. I'd pick that. JVM bytecode rewriting FTW
user142019
@FredOverflow Not? Then how does import static work?
20:21
@Zoidberg Then I would pick A. Decompile, change, compile.
@Zoidberg It imports static stuff inside normal classes.
user142019
(Correct answer is obviously C, but in real life I'd also choose A.)
user142019
@FredOverflow oh. xd
C&A...
user142019
lol
I would think that C is the answer they wanted you to check, but personally, I don't believe in inheritance from foreign sources. It just doesn't work, unless the inheritance was planned for by the author of the base class.
user142019
20:23
Only if the class is really designed to be inherited from.
correct
But that's already way beyond what most people understand. And I doubt it would be the topic of an introductory course. This is an introductory course, right?
user142019
27. What's the side-effect of making a class abstract?
D. Instantiating the class becomes impossibru.
user142019
That's true, right?
user142019
@FredOverflow it's the first series of Java lessons we got at school, and this school doesn't require any preknowledge so I'd say yes.
20:24
Then you're probably safe with C. Will you be able to see the correct answers?
user142019
Yes, in a week or so.
I know from experience that students like to argue endlessly about these kinds of quizzicals.
user142019
28. Which statement is true? // STATEMENTS ARE NEVER TRUE. EXPRESSIONS ARE.
A. An abstract method is always implemented in an abstract class.
B. An abstract method has no body. // I was confused by this because in C++ it's possible to implement a pure virtual function. :)
C. An abstract method has no parameters.
D. An abstract method can only be placed within Java interfaces.
user142019
Correct.
20:27
When do the hard questions with actual code start?
user142019
There were no hard questions. :P
When do the questions with actual code start?
user142019
There are about three questions with code.
gimme gimme gimme
> Without debating OOP on the merits, it is just not hard enough to weed out mediocre programmers. OOP in school consists mostly of memorizing a bunch of vocabulary terms like "encapsulation" and "inheritance" and taking multiple-choice quizzicles on the difference between polymorphism and overloading. Not much harder than memorizing famous dates and names in a history class, OOP poses inadequate mental challenges to scare away first-year students.
You're already our 11th customer today :)
user142019
30. Given the following code. Which of the code fragments below will correctly work (also on runtime)?
public class Student extends Person {
    public String studentNumber;
}
public class Person {
    public String name;
}

A.
    Student s = (Student) new Person();
    s.name = "Obama";

B.
    Person p = (Person) new Person(); // sigh
    s.studentNumber = "0123456"; // sigh, a string

C.
    Person p = new Student();
    ((Student) p).studentNumber = "0123456";

D.
    Student s = new Person();
20:31
A fails with a bad cast or whatever
Oh, of course, persons have no student number :)
user142019
Yes. B is compile error. C is correct. D is compile error.
C works.
There is a D? Oh, scroll down :) Yeah, static type system does not like this.
user142019
29. Given the following code. Which of the code fragments below will correctly work?
public class Student extends Person {}
public class Person {}

A.
    public void method1() {
        Student s = new Person();
        method2(s);
    }

    public void method2(Person p) {
        Student s = p;
    }

B.
    public void method1() {
        Person s = new Student();
        method2(s);
    }

    public void method2(Person p) {
        Student s = p;
    }

C.
    public void method1() {
        Student s = new Person();
A the first initialization fails.
user142019
B second init fails. :P
user142019
20:35
C init fails.
B The second initialization fails.
user142019
D is correct.
user142019
32. Which statement is correct?
B. Interfaces can extend other interfaces.
user142019
Correct, right? (At least, in Objective-C protocols can require implementation of other protocols.)
20:37
@Zoidberg yes AFAIK
Yes
user142019
34. What's the goal of garbage collection?
A. Allow for using an ArrayList to store a collection of objects. // lololol
B. Detecting and cleaning up useless files between your Java code.
C. Deleting objects you don't use anymore.
D. Deleting instance variables of objects.
user142019
None are correct.
user142019
C would require solving the halting problem.
20:39
@Zoidberg C is correct isn't it?
But they obviously want you to tick off C.
user142019
s/don't use/can't reach/ and C would be correct.
user142019
I ticked C.
@Zoidberg how would you use it if you can't reach it?
user142019
That's not the point.
user142019
20:40
The point is
@MooingDuck There are also reachable objects that you don't use anymore.
user142019
I may have a ref to an object, but I never ever use it.
@Zoidberg E Make sure your house doesn't smell.
user142019
void foo() {
    Foo foo = new Foo();
    meh(); // I don't use foo anymore (assuming ctor of foo doesn't (directly) pass this anywhere)
}
@FredOverflow then it would be acceptable for the GC to collect them no? The fact that it can't tell the difference is irrelevant.
20:40
@Zoidberg Note that it's asking the goal, not what GC really does. That's broad enough that you can probably call C a correct answer, even though it's not exactly what a GC really does.
@MooingDuck Hmm... you're probably right.
user142019
@JerryCoffin hmm ye.
@FredOverflow woo!
user142019
Ah well.
user142019
35. What's the point of constructor chaining?
20:41
Free text?
user142019
Never even heard of that term. Is it ctor delegation?
It means calling the super constructor or another constructor of the same class.
user142019
@FredOverflow no. All questions are multiple gamble with four options.
@Zoidberg yeah
"Constructor chaining is the process of calling the super class constructor by the subclass constructors in the inheritance tree when creating an object."
user142019
20:42
@FredOverflow ah ok.
user142019
35. What's the point of constructor chaining?
A. Allow for defining classes. // wat
B. Enhancing polymorphism.
C. Reusing code. // correct, I think?
D. Applying encapsulation to a ctor.
@Zoidberg C is best, but D isn't that far behind IMO
Not B. Poly has nothing to do with it.
rather, D
C or D... could be either...
20:45
I still think C > D
user142019
@ScottW xD
user142019
@MooingDuck I think C++ > D.
@Zoidberg >D
Yeah we could go nuts in this room and star all kinds of crap. Oh, wait.
What happens if you don't manually call any base class ctor in Java?
user142019
36. What's the difference between the stack and the heap?
A. Only the heap contains all objects. // implementation-defined
B. Garbage collection is only applied to the stack. // implementation-defined
C. Only the heap knows which methods were called. // implementation-defined
D. Only the stack contains a stack of all classes. // implementation-defined
user142019
20:46
This question is implementation-defined.
They want you to tick A.
user142019
I know. :P
What the hell is "a stack of all classes"?
user142019
Stack<Class>? lol
@FredOverflow Just about to ask that...
20:48
@ScottW We're talking Java here.
@ScottW Ah, but the heap does not contain anything except for objects
This room is called "Java sucks", what were you thinking? :)
@AndreiTita Default constructor of base is called. If there is none (or it's not accessible), it's a compile-time error.
user142019
40. When would you throw an exception?
A. If you can solve the error in the method you throw the exception in.
B. If you use a try-catch statement.
C. If you don't know how to deal with dangerous situations. // makes no sense; throwing an exception *is* a way of dealing with the situation
D. If you want to end a loop.
user142019
That's the last question. :)
@Zoidberg I cannot decide between C and D on question 35. What a stupid question.
user142019
20:50
C is "correct".
user142019
Again, depends on context.
user142019
I dislike using exceptions as glorified gotos. Still possible though.
user142019
@FredOverflow I ticked C.
@FredOverflow Yeah. I'm keeping my original assessment tho.
Or rather, what stupid answers :)
user142019
20:51
I think they should've made us write code.
user142019
But a multiple gamble exam is easier to examine since it's done fully automatically.
@Zoidberg That's called "expection" (as opposed to "exception") or "throwto" (as opposed to "goto").
user142019
xD
@FredOverflow lol
@Zoidberg That's why we're doing it in our large Java course as well. We have several 100 students, it would take forever to do anything else than multiple-choice quizzes.
user142019
20:53
Real programmers implement goto in Java by modifying the PC using the JNI.
@Zoidberg Modifying the PC is for case-modders.
user142019
Program counter.
user142019
At least, that's how Zoidlang works. I don't know how well it works with Java's JIT (it has one, IIRC).
@FredOverflow our code uses that everywhere :(
user142019
lol
user142019
20:54
Use break.
user142019
Or for breaking out of nested loops, use goto.
@MooingDuck I used a longjmp in C once to get out of deep recursion. Please don't tell anyone!
user142019
PHP has break x; which breaks out of the x closest loops. :P
x is an integer? cool
Does Java have named loops?
20:55
Java has break label.
Can't recall.
user142019
for ($i = 0; $i < 10; ++$i) {
    for ($j = 0; $j < 10; ++$j) {
        if ($j == 4) break 2;
    }
}
user142019
One of the very few features of PHP I like.
I'd love that in C++.
user142019
The other one is $key => $value in foreach loops.
20:56
@Zoidberg that'd be nice :(
outer:
for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
        if (j == 4) break outer;
    }
}
user142019
foreach ($my_dictionary as $key => $value) {
    // though many languages have this
}
@Zoidberg for(auto& value : my_dictionary) //C++
user142019
In this room: Java and PHP. The two worstest languages in the Universe!
user142019
@MooingDuck except .first and .second is ugly. :(
user142019
20:57
I would like this in C++:
@Zoidberg what? oh
user142019
for ({auto const& key, auto& value} : my_dictionary) {

}
user142019
REVERSE BRACE INITIALIZATION :D
user142019
(CoffeeScript has this.)
@Zoidberg (1) use references as a workaround, or (2) use a translating iterator (boost). But yeah.
user142019
20:59
In CoffeeScript I really like this:
user142019
myObject
    a: 42
    b: 1337
    c: 3.14

{a, b, c} = myObject
@Zoidberg It's called "pattern matching" :)
user142019
@FredOverflow In CoffeeScript it's called "destructing assignment".
C++ should definitely get pattern matching. Anyone up for a proposal?
user142019
It doesn't really match anything.

  last day (894 days later) »