Loading…
Programming · short notes, key points and practice questions.
Classes, constructors and destructors, inheritance, virtual functions and dynamic dispatch, overloading versus overriding, access control, static members, abstract classes, interfaces and exceptions in C++ and Java, plus Java strings and collections basics. Placement tests ask it as concept questions and as output prediction.
const T&; taking T by value would recurse foreverthis(...) or super(...) must be the first statement; Java has no destructors – the garbage collector frees memoryvirtual functions dispatch dynamically; non-virtual calls use the pointer's declared typenull goes to the most specific typevirtual base classesvirtual void f() = 0; makes a class abstract; it cannot be instantiatedfinal class cannot be extended, final method cannot be overridden; C++ friend gives access to private members"ab" == "ab" is true but new String("ab") == "ab" is falseequals for content; overriding equals requires overriding hashCode consistentlyInteger a = 127, b = 127; a == b is true, for 128 it is falsefinally runs even after return; a return in finally overrides the try's returnAnswer: A. Encapsulation
String s = "ab";
s.concat("cd");
s.toUpperCase();
System.out.print(s);Answer: C. ab
class A {
void show() { System.out.print("A"); }
}
class B extends A {
void show() { super.show(); System.out.print("B"); }
}
class C extends B {
void show() { System.out.print("C"); super.show(); }
}
// in main:
A obj = new C();
obj.show();Answer: D. CAB
struct A { A() { cout << "A"; } };
struct B : virtual A { B() { cout << "B"; } };
struct C : virtual A { C() { cout << "C"; } };
struct D : B, C { D() { cout << "D"; } };
int main() { D d; }Answer: C. ABCD
Answer: B. extends