Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!

Saumyaraj Zala

Ranch Hand
+ Follow
since Aug 06, 2012
Saumyaraj likes ...
Eclipse IDE AngularJS Java
India
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
6
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Saumyaraj Zala

Jhonson Fernando wrote:The correct answer is 7.
Here is how it is evaluated:

4*5/4+2  = 7


int x=3;
int y= ++x (4) * 5 / x-- (4) + --x (2);



According to me it should be :
int y = ++x * 5/3 + --x;
int y = 3*5/3+ --x;
int y = 3*5/3+2;

but in book it is your way.

Jhonson Fernando wrote:The correct answer is 7.
Here is how it is evaluated:

4*5/4+2  = 7


int x=3;
int y= ++x (4) * 5 / x-- (4) + --x (2);


Why do we increment x first resulting in 4. Aint it in prefix operator?
Output gets changed with precedence right?
If we ignore the precedence of postfix operator over prefix operator and start by left to right it can result in wrong output.
I dont know what i am missing here. evaluation from left to right will only happen if the precedance is same right?
What should be the output of the above expression ?


According to the operator precedance, the post fix operator should be evaluated first but in the solution the first prefix is evaluated first.
What is the correct output?
Ok, I understood the point that abstract modifier cant be appied ALWAYS as there can be default or static methods present but it gets applied sometime and that was why I was confused. I think it would be more clearer If question stated which would be ALWAYS applied.

Ganesh Patekar wrote:

Saumyaraj Zala wrote:Agreed! But there are some examples later in the excerices that dont have the abstract modifier in it and still the code compiles!
eg; public void hello();

wont this compile?

Yes It will compile. Since this is not a default Or a static method of an interface so implicitly absract modifier is applied for this method.

Even you don't need to write public modifier as implicitly It is applied to all methods of interface, let that be default Or static Or abstract method of an interface, that is why option B is correct.



So wont the answer include that abstract modifier will be implicitly applied or is it like it has not been included in answer because the abstract modifier does not always get included?

Henry Wong wrote:

Saumyaraj Zala wrote:
As fly is private in Bird, Pelican defines fly() as a new method.
When an object of Pelican is created why would fly method of Bird be executed as fly is not static? Aint it straight away??



The compiler chooses the version of the method to call based on the reference type. Since the reference is of Bird type, it will try to call the method of the Bird class. And as you mentioned, since the Pelican fly() method does not override (it hides) the Bird fly() method, it does not get called.

Henry



But the object in memory has a method which prints "Pelican". What understanding I have till now is that the reference type is only a kind of pointer, the method that is being defined in the object is what actually gets executed.

Ganesh Patekar wrote:

Saumyaraj Zala wrote:wont abstract be implicitly applied to the method?

No not to all, as It is mentioned in that answer, It was assumed to be abstract before Java 8 because since Java 8 we can have default and static methods which has their defined body in interface  and you know abstract methods can't have body so you can't say ALL interface methods implicitly have abstract modifiers as there can be default and static methods too.



Agreed! But there are some examples later in the excerices that dont have the abstract modifier in it and still the code compiles!
eg; public void hello();

wont this compile?


As fly is private in Bird, Pelican defines fly() as a new method.
When an object of Pelican is created why would fly method of Bird be executed as fly is not static? Aint it straight away??
The Question is like what modifiers are implicitly applied to all interface methods in which option saying abstract is marked incorrect.
If a interface is like:

wont abstract be implicitly applied to the method?

Should not the line no 6 be like :

The datatype of variable on the left hand side should be same as the type of array/Iterable. Integer and int are not o the same typr then why will the code compile?
Am I missing something that I will learn in next chapters?

Moreover wanted to clarify that in unary operator i++, the value first gets incremented and then it returns the origunal(old) value. Is my understanding correct?

14. Given the following class in the file /my/directory/named/A/Bird.java:
INSERT CODE HERE
public class Bird { }
Which of the following replaces INSERT CODE HERE if we compile from /my/directory?
(Choose all that apply)
A. package my.directory.named.a;
B. package my.directory.named.A;
C. package named.a;
D. package named.A;
E. package a;
F. package A;
G. Does not compile


I can make a class as

and compile it from /my/directory as :

then why is D not a correct option?

23. Which of the following are true? (Choose all that apply)
A. javac compiles a .class file into a .java file.
B. javac compiles a .java file into a .bytecode file.
C. javac compiles a .java file into a .class file.
D. Java takes the name of the class as a parameter.
E. Java takes the name of the .bytecode file as a parameter.
F. Java takes the name of the .class file as a parameter.


The name of .class file is same as class name. If D is correct why F is not correct?
Hi,

I was trying to import a package that was not on the current directly and compiler complained saying "package not found"
Current directly where Demo.java is present = C:/temp
Directly where org.open was present = C:


Then I tried command using -classpath option  i.e javac -classpath c: com\hello\Demo.java and the things worked fine.

Now I am wondering why -cp option is used at runtime as mentioned in chapter 1 of OCA8 when compiler checks for the imports at compile time itself?

In the end of page 6, chapter 1 the points are mentioned as :

Each file can contain only one class


I was a bit confused as I was pretty sure I had seen a file before having more than one class. It should have been "Each file can contain only one public class".

Same applies for

The filename must match the class name, including case, and have a .java extension


It should have been "The filename must match the public class name, including case, and have a .java extension".

Moreover, out of curiosity I was thinking whether it is possible to escape multiline line comment inside a multiline comment. I know it wont make any sense but was just thinking how compiler checks or can skip a "*/".