1) write an abstract class a ball. You must include 2 variablescommon to all balls, and at least one abstract method. Then, createtwo concrete subclasses of ball that define a specific type of balland override the abstract method.
2) 3) - Show the error in the following code:interface A {void m1();}class B implements A {void m1() {System.out.println("m1");}}4) - What is wrong in the following code?
public class Test {public static void main(String[] args) {Person[] persons = {new Person(3), new Person(4), newPerson(1)};java.util.Arrays.sort(persons);}}class Person {private int id;Person(int id) {this.id = id;}}
3) Show the output of the following code?Rational r1 = new Rational(-2, 6);System.out.println(r1.getNumerator());System.out.println(r1.getDenominator());System.out.println(r1.intValue());System.out.println(r1.doubleValue());
6) What is wrong in the following code? (Note that thecompareTo method for the Integer and Double classes was introducedin previous chapters)public class Test {public static void main(String[] args) {Number x = new Integer(3);System.out.println(x.intValue());System.out.println(x.compareTo(new Integer(4)));}}
7)
Which of the following is a correct interface? interface A { } void print() { }; abstract interface A { print(); } abstract interface A extends I1, I2 { abstract void print() { }; } interface A { void print(); } (b) (d)
5) - Show the output of following program: public class Test { public static void main(String[] args) { new A(); new B(); } } class A { int i = 7; public A() { setI (20); System.out.println("i from A is " + i); } public void setI (int i) {
1) write an abstract class a ball. You must include 2 variables common to all balls, and at least one abstract method. T
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am