Originally posted by Smitha Amey Ballikar:
1.static can be applied to : instance variables, methods,code Segments and classes
Ans:false(i feel true)
5.
byte b = 20;
char c = b;
Is not not valid casting..
From my understanding,If its a widening conversion and value is in range then no cast is needed..
Answer Given:No
What is the concept here??
SCJP 1.4, SCWCD 1.4
Originally posted by Vijay Gade:
For your third question,
Maybe one might has to think this way:
The very name given to these words are Access Modifiers. And each of them have a specific purpose -
(1) Public: <public class Hello> Any class can access this class.
(2) Protected: Only the class that extends this kind of a class has accessibility to this class (even outside the package).
(3) Private: Nothing, even within the package, can access this kind of a class.
(4) Default (when you just define <class Hello>: Only classes within the package can access this class.
So, it does not make sense to name a class with two or more modifiers. Hope this help.
-Vijay
Devender Thareja
SCEA, SCBCD, SCJP
float f1 = 1.2F;
float f2 = 1.2F;
if( f1.equals(f2))
System.out.println("We are Equal");
Does it print "We are Equal"
What is the rule of equals for primitives??
4.
Question 40.
Given the following code segments, select the ones that are legal.
A. boolean b = true;
int i = 10;
String s = b + i;
B. char c = 10;
int i = 20;
c += i;
C. String s = "Hello" ;
int i = 10;
i += s;
D. boolean b = null ;
if( b == null ){};
E. String s = "Hello" ;
int i = 10;
s += i;
F. Integer ii = new Integer(10);
int i = 10;
ii += i;
Answer Given :B,E
I feel D,E.If B is correct why not A.
5.
byte b = 20;
char c = b;
Is not not valid casting..
From my understanding,If its a widening conversion and value is in range then no cast is needed..
Answer Given:No
What is the concept here??
6.Is calling super.methodname()in any method should be the first statement or its only for constructors??
Originally posted by Priya Jothi:
So u can't compare two primitive values using equals method.It should be compared only with == operator!!.This is the rule for comparing primitive values.
SCJP 1.4, SCWCD 1.4
3.
Given the following classes declaration in the same file MyClass1.java
package mypackage;
public class MyClass1{
//Some Valid Code
}
protected class MyClass2{
//Some Valid Code
}
A. Two classes can never be declared in the same file.
B. The code Does't compile as the top most class is
protected.
C. The code compiles & MyClass2 can only be instantiated
in it's sub classes.
D. The code compiles & MyClass2 can only be instantiated
by the classes in the package 'mypackage'.
Answer given:B
quote:
--------------------------------------------------------------------------------
Originally posted by Vijay Gade:
For your third question,
Maybe one might has to think this way:
The very name given to these words are Access Modifiers. And each of them have a specific purpose -
(1) Public: <public class Hello> Any class can access this class.
(2) Protected: Only the class that extends this kind of a class has accessibility to this class (even outside the package).
(3) Private: Nothing, even within the package, can access this kind of a class.
(4) Default (when you just define <class Hello> : Only classes within the package can access this class.
So, it does not make sense to name a class with two or more modifiers. Hope this help.
-Vijay
--------------------------------------------------------------------------------
The concept here (In Smitha's example) is that the top level class can not be protected. Protected is only allowed for nested or inner classes.
Devender Thareja.
Well, I am a little confused here, as I myself am appearing for the exam, and still a learner. How is it that the top level class mentioned here is MyClass1? It definitely is not MyClass2 right? So it has to be MyClass1. Which brings us to the concept of modifiers within the same class file, as opposed to the concept of inner or nested classes.
Please clear my doubt.
With Regards<br />Arul
Originally posted by Arul Prasad:
Hi vijay
Inner class is the one which was declared inside a Class
for e.g
class MyClass
{
class MyInner
{
}
}
in the above code Myclass consider to be an outer class
MyInner is considered as a InnerClass or nested class
but inside one .java file u can have more than one classes it was not mean to inner classes
Note: u r outer class cannot be a private nor protected ,but incase of the inner classes we can make it as private or protected Got clear. .?
Devender Thareja
SCEA, SCBCD, SCJP
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |