Originally posted by Smriti Katyal:
Congratulations!!
I totally agree with you about your opinion on compiler generated error questions. I think "the missing semi colons at the end of anonymous class declaration" and such syntactical errors are not something that prove your understanding of Java.
But I know the exam is valued and has its own merits!
All the best and congratz once more!
Originally posted by Christopher Gabijan:
Congrats
Don't worry you got higher than my score..
I've been developing a lot of JAVA Based System and Application and I always don't get compiler errors cause I've used great IDE's like JBuilder and Forte(now SUN ONE), but it is also a challenge to pass SCJP on how good our compiler understanding is (to prove and to improve), and to know also the tricky/unique/out of this world class implementations (like on the SCJP Examination) that can also gives us overviews on programmers/developers/architects that do this exotic codes .
Congrats Again! what's next?
[ September 04, 2004: Message edited by: Christopher Gabijan ]
Originally posted by chowdary Thammineedi:
There Are No Traffic JAMS on the extra MILE.
- Roger Staubach
(Was he the GB Packers Coach?. F'r gimme I am not American)
Nobody wants to be a compiler. But if you think like one, you are only going to be a better programmer.
Can You Override a Variable?
Yes, you can override a variable. This is the short answer. A subclass can have a variable with the same name as a variable in the parent class. In this case, if the parent class variable is not private, the subclass variable is said to shadow the parent class variable. However, there is a significant difference between the way the Java compiler treats methods and the way it treats variables. Because of the way variables are stored in the memory allocated to an object, references to variables can be computed at compile time based on the type of the variable.
Suppose that the BookElement class defines a variable named lineCt and the subclass Chapter defines another variable named lineCt. Which value would the following code fragment print?
Chapter ch = new Chapter() ;
BookElement b = ch ; // casting to the parent class
System.out.println( b.lineCt ) ;
If you guessed that the compiler would use the lineCt variable found in the BookElement class because b is a BookElement reference, you are correct.
Remember that references to member variables are computed at compile time using the type of the reference. References to member methods are resolved at runtime using the type of the object.
Originally posted by Doyle Matt:
Hi All,
All this techy terms are getting me confused. Anyway just to simplify things the code int i = 1/2 generates a compile time constant plus both "1" and "2" are integers. so at runtime/or compile time (which ever is correct) will produce and output of 0 (an integer) and not a double 0.5.
Clear enough? Or did I add additional mistakes and confusion?
Originally posted by Peter Warde:
Matt
I'm not sure about this compile time constant. I don't think the code below is a compile time constant as the value of y would only be determined at runtime.
class Test {
int i;
Test(int y) {
i = y/2;
System.out.println(i);
}
public static void main( String args[]) {
Test t = new Test(1);
}
}
Ps does anybody know a good explanation of what is determined at compile time versus runtime
Originally posted by Swati Udas:
class Leg{}
class Fur{}
abstract class Pet {
public abstract void eat();
public abstract void sleep();
}
class Dog extends Pet {
Leg leftFront = new Leg(), rightFront = new Leg();
Leg leftRear = new Leg(), rightRear = new Leg();
Fur fur = new Fur();
public Fur shed() {return fur;}
public void eat() {}
public void sleep() {}
}
class Cat extends Dog {
public void ignoreOwner() {}
public void climbTree() {}
}
Which of the following statements is not a true statement?
a. A Cat object inherits an instance of Fur and four instances of Leg from the Dog superclass.
b. A Cat object is able to sleep and eat.
c. A Cat object is able to climb a tree.
d. The relationship between Dog and Pet is an example of an appropriate use of inheritance.
e. The relationship between Cat and Dog is an example of an appropriate use of inheritance.
f. None of the above.
The answer is given e and explainetion is as follows:
An appropriate inheritance relationship includes a subclass that "is-a" special kind of the superclass. The relationship between the Dog subclass and the Pet superclass is an example of an appropriate inheritance relationship, because a Dog "is-a" Pet. The relationship between the Cat subclass and the Dog superclass is not an example of an appropriate use of inheritance, because a Cat is not a special kind of a Dog. The goal of the OO paradigm is to develop software models that are accurate and reusable. If the software model is not accurate, then it probably is not reusable and the goals of the OO paradigm are not achieved. Code reuse and maintenance becomes increasingly difficult when inheritance is used to model inappropriate relationships. For example, suppose that somebody implements a herdSheep method in the Dog class. The Cat subclass would inherit the method and suddenly each instance of Cat would acquire the unwanted capability to make an attempt to herd sheep. It is difficult to imagine that a Cat would perform well in that role, so additional maintenance would be required to resolve the problem.
i think the xplaination and answer do not conform to each other the answer shud be D according to the above theory.Please clarify!
Which of the following statements is not a true statement?
Originally posted by Sandya Bhaskara:
what is this private protected modifier?is it same as default modifier?