sohail hussain

Ranch Hand
+ Follow
since Sep 06, 2018
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
5
Received in last 30 days
1
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by sohail hussain

vineet walia wrote:Strings are reference type in Java
. . .
Output:-

java is not fun
Java is fun!



Expected Output:-

java is not fun
java is not fun

if you create string literal it is stored in string literal pool, so again if you create the same literal object with different reference then no new object is created but instead it will internd to same object as str1 and str2 points to same object, then if change the object value and assgin str1 then it current object pointing that reference still str2 pointing to first object
5 days ago

Neha Agnihotri wrote:Which is a functional interface ?

1. It's an interface that always contains exactly one abstract method. It may contain default/static methods.
2. It's an interface that contains zero or one abstract method. It may contain default/static methods.
3. None of these.

Which one of the two statements are right? Thanks in advance!

I go with 1 and 2
Because there is a chance of one abstract method in 2.

Yan Digilov wrote:On page 291 of Head First Java, they discuss autoboxing and specify that references can be assigned to either the wrapped objected or the primitive type.  However, on the picture, they have a double reference defined with Integer and Int types being thrown in.  Is this an error or have I misunderstood the concept?

assignment requires runtime check, so an integer object reference is assigned to int which is primitive type, autoboxing and unboxing can be done at while declaring the variable not at the assignment so error at runtime because if it not initialized it contain null
So null is assigned to int variable nullpointerexception
Put j=10;
Change it like this
Int i=j;
I think it works
2 weeks ago
Can anybody help me to find ocajp-8 exam centers in Hyderabad, india
Please I am ready to take the exam
that means talking about exception propagation, if yes then checked exception are propagated with throws clause and unchecked exceptions are propagated with throw,
1 month ago

Paul Clapham wrote:

joseph hu wrote:below is correct.



Except that the comment isn't correct. That code does not throw ClassCastException.

yes you are right because superclass reference pointing to subclass object so at runtime it points to subclass object there for it can  be casted, may be I am wrong but I thought in that way it works, please any way that it cast can happen explain sombody
1 month ago

Ouadi Belmokhtar wrote:Hi guys
I would like to ask for some suggestions from your experience on taking Java certifications.
I'am preparing OCA8, I fully read OCA8 Mala Gupta's book. I scored 61/77 on mock exam provided in the book.
Now, before taking the real exam, I'm hesitating between doing more preparations by taking more mock exams in (Selikoff's OCA8 Practice Tests book) OR taking directly Enthuware mock exams !
Knowing that I don't have a significant experience in Java development
What do you think ?

you are right you must go for enthuware mocks and you are almost done your preparation according to your mocks in Mala Gupta books that's very easy to understand, try 2 to 3 mocks in enthuware then if got at least 75% then your are ready to write I am also preparing for ocajp8 since 1year am writing my ocajp in June and one more point try for Khaled mughal book for ocajp8

Campbell Ritchie wrote:

sohail hussain wrote:. . . you have to provide start index and end index to which you want to get substring

Please check the String documentation for details of overloaded methods before posting that sort of thing.

Example...
"hello".substring(2, 4)
It will print "llo" . . .

Afraid that isn't correct, as you will see from the appropriate documentation link.

I personally checked it compiled well but only difference is output is "ll" not "llo"
Because it take index less then one what you specified in substring(2,4) so on and counts index same as you specified that is on index 4 we have "l" so printed "ll"
2 months ago

Ana Yo wrote:What would "hello".substring(5) return?

you have to provide start index and end index to which you want to get substring
Example...
"hello".substring(2, 4)
It will print "llo"as the output that means 2 is the start of index where 4 is the end of index
And if you are specifying only one index that is start index then you need have" hello world" then substring (5) will print after the index 5 which is "world" as output
Hope this helpful
2 months ago

Paul Anilprem wrote:

sohail hussain wrote: I mean it's again depend on the type of access modifier using in equals() method                                            
Example... Default boolean equals() {}
Then you cannot override the equals()
This is from whizlabs mocks question which I got to know, and I personally checked it, compiled successfully,
So my question is why this diffrence has made for access modifiers, may be reason is package accessibility


Don't know what whizlab says but you can't override equals in a subclass with less than public accessibility because it is public in Object class.

yes you are right it should be public  accessibility

Campbell Ritchie wrote:Yes, it can override equals() from its superclass. It may introduce errors into the method by such overriding, but the only way to prevent such overriding is to mark the method final.

I mean it's again depend on the type of access modifier using in equals() method                                            
Example... Default boolean equals() {}
Then you cannot override the equals()
This is from whizlabs mocks question which I got to know, and I personally checked it, compiled successfully,
So my question is why this diffrence has made for access modifiers, may be reason is package accessibility

Campbell Ritchie wrote:SH: please explain your last post. I am finding it difficult to understand, but I think it is incorrect.

means if you have class c1 which has implemented equals() method from object class then another class c2 which extends c1 cannot override the equals method from c1 class to c2 class

emma roberts wrote:please why i can't override an equals method with a class how is a subclass of class object?

every class is subclass to object class so equals() method you can implement to subclass but if you have hierarchy of subclasses then it is not possible to override equals() method from class which is superclass to the class in which equals() already implemented

Petros Papatheodoru wrote:Hello, I would like some advice about how to use the main() method in my programs, and more specifically, what to put in there. Is it better to declare everything static and work like that or is it more preferable to create an instance of the main class and call another non static method and concider the new method as main() ? Also, consider this: I am given a university assignement where I have to come up with 2 algorithms that solve 2 different problems. I am asked to provide only one main method. Should I treat this main method as a merge of what would otherwise had been 2 main methods? For example for the first problem, check the arguments, then go ahead and call some methods of the one class and print the result and then continue to do something simillar for the second problem in the same main method. Or should I create 2 instances for the 2 other classes and call a non method that takes care of everything, for each of the 2 other classes?

basically if you have main() method then creates a class file for every class which contains main() method, now if you want to do one main() method then it should be test class, then for operation you want perform individual task create class for every task and use polymorphic behavior  by  creating instance of each class and call them from test class by using reference of instance to which it is pointing,, hope it helps
2 months ago