Thursday, October 11, 2007

Aptitude Questions and Answers Part 2 !!!

In recommendations to the board of trustees a tuition increase of $500 per year, the president of the university said "There were no student demonstrations over the previous increases of $300 last year and $200 the year before". If the president's statement is accurate then which of the following can be validly inferred from the information given:
I. Most students in previous years felt that the increases were justified because of increased operating costs.
II. Student apathy was responsible for the failure of students to protest the previous tuition increases.
III. Students are not likely to demonstrate over new tuition increases.

(a) I only
(b) II only
(c) I or II but not both
(d) I, II and III
(e) None

Ans. (a)

The office staff of XYZ corporation presently consists of three bookkeepers--A, B, C and 5 secretaries D, E, F, G, H. The management is planning to open a new office in another city using 2 bookkeepers and 3 secretaries of the present staff . To do so they plan to separate certain individuals who don't function well together. The following guidelines were established to set up the new office

I. Bookkeepers A and C are constantly finding fault with one another and should not be sent together to the new office as a team
II. C and E function well alone but not as a team , they should be seperated
III. D and G have not been on speaking terms and shouldn't go together
IV Since D and F have been competing for promotion they shouldn't be a team

1.If A is to be moved as one of the bookkeepers, which of the following cannot be a possible working unit.


A.ABDEH
B.ABDGH
C.ABEFH
D.ABEGH

Ans.B


2.If C and F are moved to the new office, how many combinations are possible


A.1
B.2
C.3
D.4

Ans.A


3.If C is sent to the new office, which member of the staff cannot go with C


A.B
B.D
C.F
D.G

Ans.B


4.Under the guidelines developed, which of the following must go to the new office


A.B
B.D
C.E
D.G

Ans.A


5.If D goes to the new office, which of the following is/are true


I.C cannot go
II.A cannot go
III.H must also go

A.I only
B.II only
C.I and II only
D.I and III only

Ans.D

After months of talent searching for an administrative assistant to the president of the college the field of applicants has been narrowed down to 5--A, B, C, D, E .It was announced that the finalist would be chosen after a series of all-day group personal interviews were held. The examining committee agreed upon the following procedure

I.The interviews will be held once a week
II.3 candidates will appear at any all-day interview session
III.Each candidate will appear at least once
IV.If it becomes necessary to call applicants for additonal interviews, no more 1 such applicant should be asked to appear the next week
V.Because of a detail in the written applications,it was agreed that whenever candidate B appears, A should also be present.
VI.Because of travel difficulties it was agreed that C will appear for only 1 interview.

1.At the first interview the following candidates appear A,B,D. Which of the following combinations can be called for the interview to be held next week.


A.BCD
B.CDE
C.ABE
D.ABC

Ans.B


2.Which of the following is a possible sequence of combinations for interviews in 2 successive weeks


A.ABC;BDE
B.ABD;ABE
C.ADE;ABC
D.BDE;ACD

Ans.C


3.If A ,B and D appear for the interview and D is called for additional interview the following week, which 2 candidates may be asked to appear with D?


I. A
II B
III.C
IV.E

A.I and II
B.I and III only
C.II and III only
D.III and IV only

Ans.D


4.Which of the following correctly state(s) the procedure followed by the search committee


I.After the second interview all applicants have appeared at least once
II.The committee sees each applicant a second time
III.If a third session,it is possible for all applicants to appear at least twice

A.I only
B.II only
C.III only
D.Both I and II

Ans.A

A certain city is served by subway lines A,B and C and numbers 1 2 and 3
When it snows , morning service on B is delayed When it rains or snows , service on A, 2 and 3 are delayed both in the morning and afternoon When temp. falls below 30 degrees farenheit afternoon service is cancelled in either the A line or the 3 line, but not both. When the temperature rises over 90 degrees farenheit, the afternoon service is cancelled in either the line C or the 3 line but not both.
When the service on the A line is delayed or cancelled, service on the C line which connects the A line, is delayed. When service on the 3 line is cancelled, service on the B line which connects the 3 line is delayed.


Q1. On Jan 10th, with the temperature at 15 degree farenheit, it snows all day. On how many lines will service be affected, including both morning and afternoon.


(A) 2
(B) 3
(C) 4
(D) 5

Ans. D


Q2. On Aug 15th with the temperature at 97 degrees farenheit it begins to rain at 1 PM. What is the minimum number of lines on which service will be affected?


(A) 2
(B) 3
(C) 4
(D) 5

Ans. C


Q3. On which of the following occasions would service be on the greatest number of lines disrupted.


(A) A snowy afternoon with the temperature at 45 degree farenheit
(B) A snowy morning with the temperature at 45 degree farenheit
(C) A rainy afternoon with the temperature at 45 degree farenheit
(D) A rainy afternoon with the temperature at 95 degree farenheit

Ans. B

In a certain society, there are two marriage groups, red and brown. No marriage is permitted within a group. On marriage, males become part of their wives groups; women remain in their own group. Children belong to the same group as their parents. Widowers and divorced males revert to the group of their birth. Marriage to more than one person at the same time and marriage to a direct descendant are forbidden

Q1. A brown female could have had


I. A grandfather born Red
II. A grandmother born Red
III Two grandfathers born Brown

(A) I only
(B) III only
(C) I, II and III
(D) I and II only

Ans. D


Q2. A male born into the brown group may have


(A) An uncle in either group
(B) A brown daughter
(C) A brown son
(D) A son-in-law born into red group

Ans. A


Q3. Which of the following is not permitted under the rules as stated.


(A) A brown male marrying his father's sister
(B) A red female marrying her mother's brother
(C) A widower marrying his wife's sister
(D) A widow marrying her divorced daughter's ex-husband

Ans. B


Q4. If widowers and divorced males retained their group they had upon marrying which of the following would be permissible ( Assume that no previous marriage occurred)


(A) A woman marrying her dead sister's husband
(B) A woman marrying her divorced daughter's ex-husband
(C) A widower marrying his brother's daughter
(D) A woman marrying her mother's brother who is a widower.

Ans. D

There are six steps that lead from the first to the second floor. No two people can be on the same step
Mr. A is two steps below Mr. C
Mr. B is a step next to Mr. D
Only one step is vacant ( No one standing on that step )
Denote the first step by step 1 and second step by step 2 etc.

1. If Mr. A is on the first step, Which of the following is true?

(a) Mr. B is on the second step
(b) Mr. C is on the fourth step.
(c) A person Mr. E, could be on the third step
(d) Mr. D is on higher step than Mr. C.

Ans: (d)

2. If Mr. E was on the third step & Mr. B was on a higher step than Mr. E which step must be vacant

(a) step 1
(b) step 2
(c) step 4
(d) step 5
(e) step 6

Ans: (a)

3. If Mr. B was on step 1, which step could A be on?

(a) 2&e only
(b) 3&5 only
(c) 3&4 only
(d) 4&5 only
(e) 2&4 only

Ans: (c)

4. If there were two steps between the step that A was standing and the step that B was standing on, and A was on a higher step than D , A must be on step


(a) 2
(b) 3
(c) 4
(d) 5
(e) 6

Ans: (c)


5. Which of the following is false


i. B&D can be both on odd-numbered steps in one configuration
ii. In a particular configuration A and C must either both an odd numbered steps or both an even-numbered steps
iii. A person E can be on a step next to the vacant step.

(a) i only
(b) ii only
(c) iii only
(d) both i and iii

Ans: (c)

Six swimmers A, B, C, D, E, F compete in a race. The outcome is as follows.
i. B does not win.
ii. Only two swimmers separate E & D
iii. A is behind D & E
iv. B is ahead of E , with one swimmer intervening
v. F is a head of D

1. Who stood fifth in the race ?

(a) A
(b) B
(c) C
(d) D
(e) E

Ans: (e)

2. How many swimmers separate A and F ?

(a) 1
(b) 2
(c) 3
(d) 4
(e) cannot be determined

Ans: (d)

3. The swimmer between C & E is

(a) none
(b) F
(c) D
(d) B
(e) A

Ans: (a)


4. If the end of the race, swimmer D is disqualified by the Judges then swimmer B finishes in which place

(a) 1
(b) 2
(c) 3
(d) 4
(e) 5

Ans: (b)


Five houses lettered A,B,C,D, & E are built in a row next to each other. The houses are lined up in the order A,B,C,D, & E. Each of the five houses has a colored chimney. The roof and chimney of each housemust be painted as follows.
i. The roof must be painted either green,red ,or yellow.
ii. The chimney must be painted either white, black, or red.
iii. No house may have the same color chimney as the color of roof.
iv. No house may use any of the same colors that the every next house uses.
v. House E has a green roof.
vi. House B has a red roof and a black chimney

1. Which of the following is true ?

(a) At least two houses have black chimney.
(b) At least two houses have red roofs.
(c) At least two houses have white chimneys
(d) At least two houses have green roofs
(e) At least two houses have yellow roofs

Ans: (c)

2. Which must be false ?

(a) House A has a yellow roof
(b) House A & C have different color chimney
(c) House D has a black chimney
(d) House E has a white chimney
(e) House B&D have the same color roof.

Ans: (b)

3. If house C has a yellow roof. Which must be true.

(a) House E has a white chimney
(b) House E has a black chimney
(c) House E has a red chimney
(d) House D has a red chimney
(e) House C has a black chimney

Ans: (a)

4. Which possible combinations of roof & chimney can house

I. A red roof 7 a black chimney
II. A yellow roof & a red chimney
III. A yellow roof & a black chimney

(a) I only
(b) II only
(c) III only
(d) I & II only
(e) I&II&III

Ans: (e)

Find x+2y
(i). x+y=10
(ii). 2x+4y=20

Ans: (b)

Is angle BAC is a right angle
(i) AB=2BC
(2) BC=1.5AC

Ans: (e)

Is x greater than y
(i) x=2k
(ii) k=2y

Ans: (e)

Aptitude Questions and Answers !!!

If 2x-y=4 then 6x-3y=?

(a)15
(b)12
(c)18
(d)10

Ans. (b)

If x=y=2z and xyz=256 then what is the value of x?

(a)12
(b)8
(c)16
(d)6

Ans. (b)

Pipe A can fill in 20 minutes and Pipe B in 30 mins and Pipe C can empty the same in 40 mins. If all of them work together, find the time taken to fill the tank

(a) 17 1/7 mins
(b) 20 mins
(c) 8 mins
(d) none of these

Ans. (a)

Thirty men take 20 days to complete a job working 9 hours a day. How many hour a day should 40 men work to complete the job?

(a) 8 hrs
(b) 7 1/2 hrs
(c) 7 hrs
(d) 9 hrs

Ans. (b)

Find the smallest number in a GP whose sum is 38 and product 1728

(a) 12
(b) 20
(c) 8
(d) none of these

Ans. (c)

A boat travels 20 kms upstream in 6 hrs and 18 kms downstream in 4 hrs. Find the speed of the boat in still water and the speed of the water current?

(a) 1/2 kmph
(b) 7/12 kmph
(c) 5 kmph
(d) none of these

Ans. (b)

A goat is tied to one corner of a square plot of side 12m by a rope 7m long. Find the area it can graze?

(a) 38.5 sq.m
(b) 155 sq.m
(c) 144 sq.m
(d) 19.25 sq.m

Ans. (a)

Mr. Shah decided to walk down the escalator of a tube station. He found that if he walks down 26 steps, he requires 30 seconds to reach the bottom. However, if he steps down 34 stairs he would only require 18 seconds to get to the bottom. If the time is measured from the moment the top step begins to descend to the time he steps off the last step at the bottom, find out the height of the stair way in steps?

Ans.46 steps.

The average age of 10 members of a committee is the same as it was 4 years ago, because an old member has been replaced by a young member. Find how much younger is the new member ?

Ans.40 years.

ABCE is an isosceles trapezoid and ACDE is a rectangle. AB = 10 and EC = 20. What is the length of AE?

Ans. AE = 10.

In the given figure, PA and PB are tangents to the circle at A and B respectively and the chord BC is parallel to tangent PA. If AC = 6 cm, and length of the tangent AP is 9 cm, then what is the length of the chord BC?

Ans. BC = 4 cm.

Three cards are drawn at random from an ordinary pack of cards. Find the probability that they will consist of a king, a queen and an ace.

Ans. 64/2210.

A number of cats got together and decided to kill between them 999919 mice. Every cat killed an equal number of mice. Each cat killed more mice than there were cats. How many cats do you think there were ?

Ans. 991.

If Log2 x - 5 Log x + 6 = 0, then what would the value / values of x be?

Ans. x = e2 or e3.

The square of a two digit number is divided by half the number. After 36 is added to the quotient, this sum is then divided by 2. The digits of the resulting number are the same as those in the original number, but they are in reverse order. The ten's place of the original number is equal to twice the difference between its digits. What is the number?

Ans. 46

Can you tender a one rupee note in such a manner that there shall be total 50 coins but none of them would be 2 paise coins.?

Ans. 45 one paisa coins, 2 five paise coins, 2 ten paise coins, and 1 twenty-five paise coins.

A monkey starts climbing up a tree 20ft. tall. Each hour, it hops 3ft. and slips back 2ft. How much time would it take the monkey to reach the top?

Ans.18 hours.

What is the missing number in this series?
8 2 14 6 11 ? 14 6 18 12


Ans. 9

A certain type of mixture is prepared by mixing brand A at Rs.9 a kg. with brand B at Rs.4 a kg. If the mixture is worth Rs.7 a kg., how many kgs. of brand A are needed to make 40kgs. of the mixture?

Ans. Brand A needed is 24kgs.

A wizard named Nepo says "I am only three times my son's age. My father is 40 years more than twice my age. Together the three of us are a mere 1240 years old." How old is Nepo?

Ans. 360 years old.

One dog tells the other that there are two dogs in front of me. The other one also shouts that he too had two behind him. How many are they?

Ans. Three.

A man ate 100 bananas in five days, each day eating 6 more than the previous day. How many bananas did he eat on the first day?

Ans. Eight.

If it takes five minutes to boil one egg, how long will it take to boil four eggs?

Ans. Five minutes.

The minute hand of a clock overtakes the hour hand at intervals of 64 minutes of correct time. How much a day does the clock gain or lose?

Ans. 32 8/11 minutes.

Solve for x and y: 1/x - 1/y = 1/3, 1/x2 + 1/y2 = 5/9.

Ans. x = 3/2 or -3 and y = 3 or -3/2.

Daal is now being sold at Rs. 20 a kg. During last month its rate was Rs. 16 per kg. By how much percent should a family reduce its consumption so as to keep the expenditure fixed?

Ans. 20 %.

Find the least value of 3x + 4y if x2y3 = 6.

Ans. 10.

Can you find out what day of the week was January 12, 1979?

Ans. Friday.

A garrison of 3300 men has provisions for 32 days, when given at a rate of 850 grams per head. At the end of 7 days a reinforcement arrives and it was found that now the provisions will last 8 days less, when given at the rate of 825 grams per head. How, many more men can it feed?

Ans. 1700 men.

From 5 different green balls, four different blue balls and three different red balls, how many combinations of balls can be chosen taking at least one green and one blue ball?

Ans. 3720.

Three pipes, A, B, & C are attached to a tank. A & B can fill it in 20 & 30 minutes respectively while C can empty it in 15 minutes. If A, B & C are kept open successively for 1 minute each, how soon will the tank be filled?

Ans. 167 minutes.

For a motorist there are three ways going from City A to City C. By way of bridge the distance is 20 miles and toll is $0.75. A tunnel between the two cities is a distance of 10 miles and toll is $1.00 for the vehicle and driver and $0.10 for each passenger. A two-lane highway without toll goes east for 30 miles to city B and then 20 miles in a northwest direction to City C.

1. Which is the shortest route from B to C


(a) Directly on toll free highway to City C
(b) The bridge
(c) The Tunnel
(d) The bridge or the tunnel
(e) The bridge only if traffic is heavy on the toll free highway

Ans. (a)


2. The most economical way of going from City A to City B, in terms of toll and distance is to use the


(a) tunnel
(b) bridge
(c) bridge or tunnel
(d) toll free highway
(e) bridge and highway

Ans. (a)


3. Jim usually drives alone from City C to City A every working day. His firm deducts a percentage of employee pay for lateness. Which factor would most influence his choice of the bridge or the tunnel ?


(a) Whether his wife goes with him
(b) scenic beauty on the route
(c) Traffic conditions on the road, bridge and tunnel
(d) saving $0.25 in tolls
(e) price of gasoline consumed in covering additional 10 miles on the bridge

Ans. (a)


4. In choosing between the use of the bridge and the tunnel the chief factor(s) would be:

I. Traffic and road conditions
II. Number of passengers in the car
III. Location of one's homes in the center or outskirts of one of the cities
IV. Desire to save $0.25

(a) I only
(b) II only
(c) II and III only
(d) III and IV only
(e) I and II only

The letters A, B, C, D, E, F and G, not necessarily in that order, stand for seven consecutive integers from 1 to 10
D is 3 less than A
B is the middle term
F is as much less than B as C is greater than D
G is greater than F

1. The fifth integer is

(a) A
(b) C
(c) D
(d) E
(e) F

Ans. (a)


2. A is as much greater than F as which integer is less than G

(a) A
(b) B
(c) C
(d) D
(e) E

Ans. (a)


3. If A = 7, the sum of E and G is

(a) 8
(b) 10
(c) 12
(d) 14
(e) 16

Ans. (a)

4. A - F = ?

(a) 1
(b) 2
(c) 3
(d) 4
(e) Cannot be determined

Ans. (a)


5. An integer T is as much greater than C as C is greater than E. T can be written as A + E. What is D?

(a) 2
(b) 3
(c) 4
(d) 5
(e) Cannot be determined

Ans. (a)


6. The greatest possible value of C is how much greater than the smallest possible value of D?

(a) 2
(b) 3
(c) 4
(d) 5
(e) 6

Ans. (a)

1. All G's are H's
2. All G's are J's or K's
3. All J's and K's are G's
4. All L's are K's
5. All N's are M's
6. No M's are G's



1. If no P's are K's, which of the following must be true?


(a) All P's are J's
(b) No P is a G
(c) No P is an H
(d) If any P is an H it is a G
(e) If any P is a G it is a J

Ans. (a)


2. Which of the following can be logically deduced from the conditions stated?


(a) No M's are H's
(b) No M's that are not N's are H's
(c) No H's are M's
(d) Some M's are H's
(e) All M's are H's

Ans. (a)


3. Which of the following is inconsistent with one or more of the conditions?


(a) All H's are G's
(b) All H's that are not G's are M's
(c) Some H's are both M's and G's
(d) No M's are H's
(e) All M's are H's

Ans. (a)


4. The statement "No L's are J's" is

I. Logically deducible from the conditions stated
II. Consistent with but not deducible from the conditions stated
III. Deducible from the stated conditions together with the additional statement "No J's are K's"

(a) I only
(b) II only
(c) III only
(d) II and III only
(e) Neither I, II nor III

Ans. (a)

In country X, democratic, conservative and justice parties have fought three civil wars in twenty years. TO restore stability an agreement is reached to rotate the top offices President, Prime Minister and Army Chief among the parties so that each party controls one and only one office at all times. The three top office holders must each have two deputies, one from each of the other parties. Each deputy must choose a staff composed of equally members of his or her chiefs party and member of the third party.

1. When Justice party holds one of the top offices, which of the following cannot be true


(a) Some of the staff members within that office are justice party members
(b) Some of the staff members within that office are democratic party members
(c) Two of the deputies within the other offices are justice party members
(d) Two of the deputies within the other offices are conservative party members
(e) Some of the staff members within the other offices are justice party members.

Ans. (a)


2. When the democratic party holds presidency, the staff of the prime minister's deputies are composed

I. One-fourth of democratic party members
II. One-half of justice party members and one-fourth of conservative party members
III. One-half of conservative party members and one-fourth of justice party members.

(a) I only
(b) I and II only
(c) II or III but not both
(d) I and II or I and III
(e) None of these

Ans. (a)


3. Which of the following is allowable under the rules as stated:


(a) More than half of the staff within a given office belonging to a single party
(b) Half of the staff within a given office belonging to a single party
(c) Any person having a member of the same party as his or her immediate superior
(d) Half the total number of staff members in all three offices belonging to a single party
(e) Half the staff members in a given office belonging to parties different from the party of the top office holder in that office.

Ans. (a)


4. The office of the Army Chief passes from Conservative to Justice party. Which of the following must be fired.


(a) The democratic deputy and all staff members belonging to Justice party
(b) Justice party deputy and all his or hers staff members
(c) Justice party deputy and half of his Conservative staff members in the chief of staff office
(d) The Conservative deputy and all of his or her staff members belonging to Conservative party
(e) No deputies and all staff members belonging to conservative parties.

Ans. (a)

Interview Questions on Core Java Part 4

What is the range of the char type?
The range of the char type is 0 to 2^16 - 1.

What is the range of the short type?
The range of the short type is -(2^15) to 2^15 - 1.

Why isn’t there operator overloading?
Because C++ has proven by example that operator overloading makes code almost impossible to maintain.

What does it mean that a method or field is “static”?
Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class.
Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That’s how library methods like System.out.println() work. out is a static field in the java.lang.System class.

Is null a keyword?
The null value is not a keyword.

Which characters may be used as the second character of an identifier,but not as the first character of an identifier?
The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier.

Is the ternary operator written x : y ? z or x ? y : z ?
It is written x ? y : z.

How is rounding performed under integer division?
The fractional part of the result is truncated. This is known as rounding toward zero.

If a class is declared without any access modifiers, where may the class be accessed?
A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.

Does a class inherit the constructors of its superclass?
A class does not inherit constructors from any of its superclasses.

Name the eight primitive Java types.
The eight primitive types are byte, char, short, int, long, float, double, and boolean.

What restrictions are placed on the values of each case of a switch statement?
During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.

What is the difference between a while statement and a do statement?
A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.

What modifiers can be used with a local inner class?
A local inner class may be final or abstract.

When does the compiler supply a default constructor for a class?
The compiler supplies a default constructor for a class if no other constructors are provided.

If a method is declared as protected, where may the method be accessed?
A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

What are the legal operands of the instanceof operator?
The left operand is an object reference or null value and the right operand is a class, interface, or array type.

Are true and false keywords?
The values true and false are not keywords.

What happens when you add a double value to a String?
The result is a String object.

What is the diffrence between inner class and nested class?
When a class is defined within a scope od another class, then it becomes inner class.
If the access modifier of the inner class is static, then it becomes nested class.

Can an abstract class be final?
An abstract class may not be declared as final

What is numeric promotion?
Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In numerical promotion, byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required

What is the difference between a public and a non-public class?
A public class may be accessed outside of its package. A non-public class may not be accessed outside of its package.

To what value is a variable of the boolean type automatically initialized?
The default value of the boolean type is false

What is the difference between the prefix and postfix forms of the ++ operator?
The prefix form performs the increment operation and returns the value of the increment operation. The postfix form returns the current value all of the expression and then performs the increment operation on that value.

What restrictions are placed on method overriding?
Overridden methods must have the same name, argument list, and return type.
The overriding method may not limit the access of the method it overrides.
The overriding method may not throw any exceptions that may not be thrown by the overridden method.

Interview Questions on Core Java Part 3

Can a method inside a Interface be declared as final?
No not possible. Doing so will result in compilation error. public and abstract are the only applicable modifiers for method declaration in an interface.

Can an Interface implement another Interface?
Interfaces doesn’t provide implementation hence a interface cannot implement another interface.

Can an Interface extend another Interface?
Yes an Interface can inherit another Interface, for that matter an Interface can extend more than one Interface.

Can a Class extend more than one Class?
Not possible. A Class can extend only one class but can implement any number of Interfaces.

Why is an Interface be able to extend more than one Interface but a Class can’t extend more than one Class?
Basically Java doesn’t allow multiple inheritance, so a Class is restricted to extend only one Class. But an Interface is a pure abstraction model and doesn’t have inheritance hierarchy like classes(do remember that the base class of all classes is Object). So an Interface is allowed to extend more than one Interface.

Can an Interface be final?
Not possible. Doing so so will result in compilation error.

Can a class be defined inside an Interface?
Yes it’s possible.

Can an Interface be defined inside a class?
Yes it’s possible.

What is a Marker Interface?
An Interface which doesn’t have any declaration inside but still enforces a mechanism.

Which Object-Oriented Concept is achieved by using overloading and overriding?
Polymorphism.

If i only change the return type, does the method become overloaded?
No it doesn’t. There should be a change in method arguments for a method to be overloaded.

Why does Java not support operator overloading?
Operator overloading makes the code very difficult to read and maintain. To maintain code simplicity, Java doesn’t support operator overloading.

Can we define private and protected modifiers for variables in interfaces?
No

What is Externalization?
Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in)

What modifiers are allowed for methods in an Interface?
Only public and abstract modifiers are allowed for methods in interfaces.

What is a local, member and a class variable?
Variables declared within a method are “local” variables.
Variables declared within the class i.e not within any methods are “member” variables (global variables).
Variables declared within the class i.e not within any methods and are defined as “static” are class variables

What is an abstract method?
An abstract method is a method whose implementation is deferred to a subclass.

What value does read() return when it has reached the end of a file?
The read() method returns -1 when it has reached the end of a file.

Can a Byte object be cast to a double value?
No, an object cannot be cast to a primitive value.

What is the difference between a static and a non-static inner class?
A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.

What is an object’s lock and which object’s have locks?
An object’s lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object’s lock. All objects and classes have locks. A class’s lock is acquired on the class’s Class object.

What is the % operator?
It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand.

When can an object reference be cast to an interface reference?
An object reference be cast to an interface reference when the object implements the referenced interface.

Which class is extended by all other classes?
The Object class is extended by all other classes.

Which non-Unicode letter characters may be used as the first character of an identifier?
The non-Unicode letter characters $ and _ may appear as the first character of an identifier

What restrictions are placed on method overloading?
Two methods may not have the same name and argument list but different return types.

What is casting?
There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.

What is the return type of a program’s main() method?
void.

If a variable is declared as private, where may the variable be accessed?
A private variable may only be accessed within the class in which it is declared.

What do you understand by private, protected and public?
These are accessibility modifiers. Private is the most restrictive, while public is the least restrictive. There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package.

What is Downcasting ?
Downcasting is the casting from a general to a more specific type, i.e. casting down the hierarchy

What modifiers may be used with an inner class that is a member of an outer class?
A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.

How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.

What restrictions are placed on the location of a package statement within a source code file?
A package statement must appear as the first line in a source code file (excluding blank lines and comments).

What is a native method?
A native method is a method that is implemented in a language other than Java.

What are order of precedence and associativity, and how are they used?
Order of precedence determines the order in which operators are evaluated in expressions. Associativity determines whether an expression is evaluated left-to-right or right-to-left

Can an anonymous class be declared as implementing an interface and extending a class?
An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.

Interview Questions on Core Java Part 2

What is a Java package and how is it used?
A Java package is a naming context for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces. Packages are also used to organize related classes and interfaces into a single API unit and to control accessibility to these classes and interfaces.

What modifiers may be used with a top-level class?
A top-level class may be public, abstract, or final.

What is the difference between an if statement and a switch statement?
The if statement is used to select among two alternatives. It uses a boolean expression to decide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternative should be executed.

What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. import java.net.* versus import java.net.Socket)?
It makes no difference in the generated class files since only the classes that are actually used are referenced by the generated class file. There is another practical benefit to importing single classes, and this arises when two (or more) packages have classes with the same name. Take java.util.Timer and javax.swing.Timer, for example. If I import java.util.* and javax.swing.* and then try to use “Timer”, I get an error while compiling (the class name is ambiguous between both packages). Let’s say what you really wanted was the javax.swing.Timer class, and the only classes you plan on using in java.util are Collection and HashMap. In this case, some people will prefer to import java.util.Collection and import java.util.HashMap instead of importing java.util.*. This will now allow them to use Timer, Collection, HashMap, and other javax.swing classes without using fully qualified class names in.

Can a method be overloaded based on different return type but same argument type ?
No, because the methods can be called without using their return type in which case there is ambiquity for the compiler

What happens to a static var that is defined within a method of a class ?
Can’t do it. You’ll get a compilation error

How many static init can you have ?
As many as you want, but the static initializers and class variable initializers are executed in textual order and may not refer to class variables declared in the class whose declarations appear textually after the use, even though these class variables are in scope.

What is the difference between method overriding and overloading?
Overriding is a method with the same name and arguments as in a parent, whereas overloading is the same method name but different arguments

What is constructor chaining and how is it achieved in Java ?
A child object constructor always first needs to construct its parent (which in turn calls its parent constructor.). In Java it is done via an implicit call to the no-args constructor as the first statement.

What is the difference between the Boolean & operator and the && operator?
If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.

Which Java operator is right associative?
The = operator is right associative.

Can a double value be cast to a byte?
Yes, a double value can be cast to a byte.

What is the difference between a break statement and a continue statement?
A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.

Can a for statement loop indefinitely?
Yes, a for statement can loop indefinitely. For example, consider the following: for(;;) ;

To what value is a variable of the String type automatically initialized?
The default value of an String type is null.

What is the difference between a field variable and a local variable?
A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.

How are this() and super() used with constructors?
this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.

What does it mean that a class or member is final?
A final class cannot be inherited. A final method cannot be overridden in a subclass.
A final field cannot be changed after it’s initialized, and it must include an initializer statement where it’s declared.

What does it mean that a method or class is abstract?
An abstract class cannot be instantiated. Abstract methods may only be included in abstract classes.However, an abstract class is not required to have any abstract methods, though most of them do.Each subclass of an abstract class must override the abstract methods of its superclasses or it also shouldbe declared abstract.

What is a transient variable?
transient variable is a variable that may not be serialized.

How does Java handle integer overflows and underflows?
It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.

What is the difference between the >> and >>> operators?
The >> operator carries the sign bit when shifting right. The >>> zero-fills bits that have been shifted out.

Interview Questions on Core Java Part 1

What is the impact of declaring a method as final?
A method declared as final can’t be overridden. A sub-class can’t have the same method signature with a different implementation.

What is the purpose of declaring a variable as final?
A final variable’s value can’t be changed. final variables should be initialized before using them.

I don’t want my class to be inherited by any other class. What should i do?
You should declared your class as final. But you can’t define your class as final, if it is an abstract class. A class declared as final can’t be extended by any other class.

Can you give few examples of final classes defined in Java API?
java.lang.String,java.lang.Math are final classes.

How is final different from finally and finalize?
final is a modifier which can be applied to a class or a method or a variable. final class can’t be inherited, final method can’t be overridden and final variable can’t be changed.
finally is an exception handling code section which gets executed whether an exception is raised or not by the try block code segment.
finalize() is a method of Object class which will be executed by the JVM just before garbage collecting object to give a final chance for resource releasing activity.

Can a class be declared as static?
No a class cannot be defined as static. Only a method,a variable or a block of code can be declared as static.

When will you define a method as static?
When a method needs to be accessed even before the creation of the object of the class then we should declare the method as static.

What are the restriction imposed on a static method or a static block of code?
A static method should not refer to instance variables without creating an instance and cannot use “this” operator to refer the instance.

I want to print “Hello” even before main is executed. How will you acheive that?
Print the statement inside a static block of code. Static blocks get executed when the class gets loaded into the memory and even before the creation of an object. Hence it will be executed before the main method. And it will be executed only once.

What is the importance of static variable?
static variables are class level variables where all objects of the class refer to the same variable. If one object changes the value then the change gets reflected in all the objects.

Can we declare a static variable inside a method?
Static varaibles are class level variables and they can’t be declared inside a method. If declared, the class will not compile.

What is an Abstract Class and what is it’s purpose?
A Class which doesn’t provide complete implementation is defined as an abstract class. Abstract classes enforce abstraction.

Can a abstract class be declared final?
Not possible. An abstract class without being inherited is of no use and hence will result in compile time error.

What is use of a abstract variable?
Variables can’t be declared as abstract. only classes and methods can be declared as abstract.

Can you create an object of an abstract class?
Not possible. Abstract classes can’t be instantiated.

Can a abstract class be defined without any abstract methods?
Yes it’s possible. This is basically to avoid instance creation of the class.

Class C implements Interface I containing method m1 and m2 declarations. Class C has provided implementation for method m2. Can i create an object of Class C?
No not possible. Class C should provide implementation for all the methods in the Interface I. Since Class C didn’t provide implementation for m1 method, it has to be declared as abstract. Abstract classes can’t be instantiated.