Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

gzw0733

Greenhorn
+ Follow
since May 28, 2001
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
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by gzw0733

First thanks all the people share the words with me.
That meant Boolean isn't a reserve word,only a type. it is completely different from boolena.
isn't ?
I think I caught your meaning.
First I thanks for your patient,you are so kind ,and I will call you Mrs not Mr.I think you didn't note the static method brake() is override .You said the static method cn't be override.but.....
class vehicle{
public String color = "vehicle-color";
public void drive(){
System.out.println("vehicle:drive");
}
public static void brake() {
System.out.println("vehicle:brake");
}
}
class car extends vehicle{
public String color = "car-color";
public void drive(){
System.out.println(" car:drive");
}
public static void brake() {
System.out.println("car:brake");
}
}
public class Test12{
public static void main(String args[]){
vehicle v;
car c;
v=new vehicle();
c=new car();
System.out.println("---- first object ------");
v.drive();
v.brake();
System.out.println(v.color);
System.out.println("---- second object ------");
c.drive();
c.brake();
System.out.println(c.color);
v=c;
System.out.println("---- variable of first object now points to second object, but is of type first object ------");
v.drive();
v.brake();
System.out.println(v.color);
}
}
hi friend

class A{
int i;
A(int i){this.i=i*2;}
}
hi friend

class B extends A{
public static void main(String arg[]){
B b=new B(2);
}
B(int i){System.out.println(i);}
}
select the right answer when you compile the class B.
a) The instance variable i is set to 4.
b) The instance variable i is set to 2.
c) The instance variable i is set to 0.
d) this code will not compile .
the given answer is d:
the given explaination:
Because B's constructor is implicitly calls A's no-args
constructor,and such a constructor is not defined.

I dont know the explaination clarely.At least I think when the method
of subclass use 'super' keyword ( eg:supper(int i) ),the method
explictly call the supperclass's method .Is it right?
Hi sona nagee !though I agree with .
But give a explaination about the code bellowed which from Axel Janssen (you can find the code of his in gzw0733's "which method will be use?")
class vehicle{
public String color = "vehicle-color";
public void drive(){
System.out.println("vehicle:drive");
}
public static void brake() {
System.out.println("vehicle:brake");
}
}
class car extends vehicle{
public String color = "car-color";
public void drive(){
System.out.println(" car:drive");
}
public static void brake() {
System.out.println("car:brake");
}
}
public class Test12{
public static void main(String args[]){
vehicle v;
car c;
v=new vehicle();
c=new car();
System.out.println("---- first object ------");
v.drive();
v.brake();
System.out.println(v.color);
System.out.println("---- second object ------");
c.drive();
c.brake();
System.out.println(c.color);
v=c;
System.out.println("---- variable of first object now points to second object, but is of type first object ------");
v.drive();
v.brake();
System.out.println(v.color);
}
}

hi friend.pls read the code bellowed.
public class exampl{
public Boolean flags[]=new Boolean[4];
public static void main(){
example E=new example();
System.out.println("flag is "+E.flag[1]);
}
}
the given choice is :
A) the text "flag is false" is written out to standard output.
B) the text "flag is null" is written out to standard output.
the given answer is B.
But I think A is right .Because the each element of boolean array will be initialized with a default value ( in this case it is "false")
can a static method be override.
read the code bellow:select the right choice.
class vehicle{
public void drive(){
System.out.println("vehicle:drive");
}
}
class car extends vehicle{
public void dirve(){
System.out.println(" car:drive");
}
}
public class test{
public static void main(String args[]){
vehicle v;
car c;
v=new vehicle();
c=new car();
v.drive();
c.drive();
v=c;
v.drive();
}
}
given choice:
A: vehicle:dirve
car:drive
car:drive
B: vehicle:drive
car:drive
vehicle:drive
the given answer:A
In my option A is right.but saw a similar question(one of simulate mock
exam) ,in which after the "v=c v.drive" ,the compile print out
"vehicle:drive"
now I am not so sure now,which method shoud to use ,the type of c or the instance of c?
I beg your explaination sincerely..........