GradePack

    • Home
    • Blog
Skip to content
bg
bg
bg
bg

GradePack

What is the output of the following code?     class A {    …

What is the output of the following code?     class A {               void foo() {  System.out.println(“1”); }               public A() {  System.out.println(“2”); foo();    }     }     class B extends A {               public B() { System.out.println(“3”);  }               void foo() { System.out.println(“4”);  }     }      public class Client {               public static void main(String [] args) {                              new B();               }    }

Read Details

Assuming list is non-empty, does this code compile or not? E…

Assuming list is non-empty, does this code compile or not? Explain.   public void func(List list){       list.add(“Hello”);    }

Read Details

Given two objects a and b such that a.equals(b) is true. Sho…

Given two objects a and b such that a.equals(b) is true. Should a.hashCode() and b.hashCode() be also equal? Justify your answer. Yes No Justification:

Read Details

Given the class hierarchy below. Could the symmetry of equal…

Given the class hierarchy below. Could the symmetry of equals() be violated? If yes, provide client code that demonstrates that.   class A {   int x;   public A(int x) {this.x = x;}   public boolean equals(Object o) {        if (!(o instanceof A)) return false;        A a = (A)o;        return this.x == a.x;   }        } class B extends A {   int y;   public B(int x, int y) {super(x); this.y = y;}   public boolean equals(Object o) {        if (!(o instanceof B)) return false;        B b = (B)o;        return super.equals(o) && this.y == b.y;   } }                

Read Details

Does the code below compile? Explain.   public class Utils…

Does the code below compile? Explain.   public class Utils {      public static void main(String[] args ) throws Exception {                           E e = new E();    } }

Read Details

What is the output of the code below? Explain. (Note: there…

What is the output of the code below? Explain. (Note: there are no compilation errors)   class A {                public int x;                public A(int x) { this.x = x; }                public String toString() { return “x = ” + x; } }   class Super {   public A a;   public Super() {                System.out.println(“Super()”);                foo();   }   public Super (A a) {                System.out.println(“Super(A a)”);                this.a = a;                foo();   }   public void foo() {                System.out.println(“Super.foo()”);                System.out.println(a);   } }   public class Sub extends Super {   public A a;   public Sub() {                System.out.println(“Sub()”);                foo();   }   public Sub (A a) {                System.out.println(“Sub(A a)”);                this.a = a;                foo();   }   @Override public void foo() {                    System.out.println(“Sub.foo()”);                System.out.println(a);   } } public static void main(String[] args) { new Super(); }  

Read Details

Given the class hierarchy below. Could the symmetry of equal…

Given the class hierarchy below. Could the symmetry of equals() be violated? If yes, provide client code that demonstrates that.   class A {   int x;   public A(int x) {this.x = x;}   public boolean equals(Object o) {        if (!(o instanceof A)) return false;        A a = (A)o;        return this.x == a.x;   }        } class B extends A {   public B(int x) {super(x); }   public boolean equals(Object o) {        if (!(o instanceof B)) return false;        B b = (B)o;        return super.equals(o);   } }                

Read Details

Given the class hierarchy below. Could the symmetry of equal…

Given the class hierarchy below. Could the symmetry of equals() be violated? If yes, provide client code that demonstrates that.   class A {   int x;   public A(int x) {this.x = x;}   public boolean equals(Object o) {        if (!(o instanceof A)) return false;        A a = (A)o;        return this.x == a.x;   }        } class B extends A {   int y;   public B(int x, int y) {super(x); this.y = y;}   public boolean equals(Object o) {        if (!(o instanceof B)) return false;        B b = (B)o;        return super.equals(o);   } }

Read Details

What characteristic defines the graph of a polynomial functi…

What characteristic defines the graph of a polynomial function in terms of breaks or holes?

Read Details

What is the process used to divide polynomials, similar to d…

What is the process used to divide polynomials, similar to dividing numbers?

Read Details

Posts pagination

Newer posts 1 … 30,844 30,845 30,846 30,847 30,848 … 86,503 Older posts

GradePack

  • Privacy Policy
  • Terms of Service
Top