You are on page 1of 3

Try It Yourself

JAVA: Inheritance 1. 2. 3. 4. Why does compiler enforce super() or this() be the first statement in a constructor? Is inheritance used only for the sake of reusability? Do we need protected access specifier if classes are not going to be in any package? The code listed below prints R.printS1 S.printS2, Why?

class R { private void printS1() {System.out.print("R.printS1 ");} protected void printS2() {System.out.print("R.printS2");} protected void printS1S2() {printS1();printS2();} } class S extends R { private void printS1() {System.out.print("S.printS1 ");} protected void printS2() {System.out.print("S.printS2 ");} public static void main(String[] args) { new S().printS1S2(); }} 5. Java does not support multiple inheritance. What is the problem with multiple inheritance? Inner Classes 1. If static inner classes are just about name of the class being tied to the outer class, why do we need it? We can use packages instead. 2. Can all inner classes access private members of the enclosing class? How about outer class- can it access members of inner class? 3. Can you identify a real life example where an anonymous inner class is useful? 4. How many inner class instances can be associated with the same outer instance? 5. Which print statement will end up in compilation error? class Q { int x=0; final int y=0; private int z=0; void xyz() {

int a=0; final int b=0; class R { R() { System.out.println(x); System.out.println(b); System.out.println(a); System.out.println(y); System.out.println(z); } } } } Exceptions 1. Exceptions occur only at runtime. (true/false) 2. Given the two methods: void f() throws IOException void g() throws RuntimeException Where will the compiler force you to handle exception explicitly? Why? 3. How can you make an application completely exception-proof? 4. You have 2 classes A and B. Class B uses the services of class A. Now you copy the classes in another machine and find that A.class is corrupt. What will happen when you execute B without A? 5. One advantage of using exception is to reduce the usage of if statements. (true/false)

Data Structures: 1) There is a singing competition for children going to be conducted at a local club. Parents have been asked to arrive at least an hour before and register their childrens names with the Program Manager. Whenever a participant registers, the Program Manager has to position the name of the person in a list in alphabet order. Write a program to help the Program Manager do this by placing the name in the right place each time the Program Manger enters a name. 2) For the singing completion mentioned in the question above, the Event Manager has to send participants to the stage to perform in the order in which they registered. Write a program that will help the Event Manager know who to call to the stage to perform.

DID YOU KNOW?? 1) Mark Zuckerberg, the founder of Facebook is red-green color-blind and Blue is generally one of the colours preferred as background as it makes the content easier to read.(Now you know why you see all of blue on Facebook!) 2) The first microprocessor 4004 was produced by Intel(shortened version of Intergrated Electronics) for a Japanese calculator manufacturer called Busicomp. The principal designers were Federico Faggin and Ted Hoff of Intel, Masatoshi Shima from Busicomp and Stanley Mazor

3) The first item listed on eBay was a Broken Laser Pointer and it was sold for $14.83 4) Googles first tweet was Im 01100110 01100101 01100101 01101100 01101001 01101110 01100111 00100000 01101100 01110101 01100011 01101011 01111001 00001010. (Pretty Geeky huh!). The binary translation reads to Im feeling lucky(The phrase you find on Googles homepage!!!)

5) The name Apple McIntosh was suggested by Apple employee Jef Raskin .It was inspired from his favorite variety of apple the McIntosh 6) Chewing gums are banned in Singapore and chewing it will get you in trouble .This was done in a bid to keep the streets of the city clean. If you ever happen to travel there stick to a mint!(Note: It can be chewed if a doctor prescribes it for you ) 7) The king of hearts is the only king without a mustache

Thought for the week: Begin with the end in mind is based on the principle that all things are created twice. Theres a mental or first creation, and a physical or second creation to all things. The carpenters rule is to measure twice, cut once. You have to make sure that the blueprint, the first creation, is really what you want, that youve thought everything through. Then you put it into bricks and mortar. Stephen Covey

You might also like