Question

The method m() of class B overrides the m() method of class A, true or false? class A int i; public void maint i) { this.is }

What is the output of the following code public class Foo { public static void main(String[] args) { Person person = new Pers

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The method m() of class B overrides the m() method of class A, true or false?
class A{
int i;
public void m(int i)
{
this.i=i;
}
}
class B extends A

{
public void m(String s)

{
  
}
}

ANSWER: false

For the following code, which statment is correct?
public class Test
{
   public static void main(String[] args)
   {
   Object a1=new A();
   Object a2=new Object();
   System.out.println(a1);
   System.out.println(a2);
      
   }
}
class A
{
int x;
@Override
public String toString()
{
return "A's x is"+x;
}
}

ANSWER:  option -B

when executing System.out.println(a1) the toString() method in A class invoked.

What is the output of the following code:
public class Foo
{
public static void main(String[] args)
{
Person person=new Person();
person.printPerson();
  
Student student =new Student();
student.printPerson();
}
}
class Student extends Person
{
private String getInfo()
{
return "Student";
}
}
class Person
{
private String getInfo()
{
return "Person";
}
public void printPerson()
{
System.out.print(getInfo()+" ");
}
}

ANSWER: option - C

Person Person

Given the following code, which line has compile error.
public class Test
{
public static void main(String[] args)
{
m(new GraduateStudent());
m(new Student());
m(new Person());
}
public static void m(Student x)
{
System.out.println(x.toString());
}
}
class GraduateStudent extends Student{
}
class Student extends Person
{
@Override
public String toString()
{
return "Student";
}
  
}
class Person extends Object
{
@Override
public String toString()
{
return "Person";
}
  
}

ANSWER: option -C

m(new Person());

Add a comment
Know the answer?
Add Answer to:
The method m() of class B overrides the m() method of class A, true or false?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • What is wrong with the following Java Code. public class TestEdible { abstract class Animal {...

    What is wrong with the following Java Code. public class TestEdible { abstract class Animal { /** Return animal sound */ public abstract String sound(); } class Chicken extends Animal implements Edible { @Override public String howToEat() { return "Chicken: Fry it"; } @Override public String sound() { return "Chicken: cock-a-doodle-doo"; } } class Tiger extends Animal { @Override public String sound() { return "Tiger: RROOAARR"; } } abstract class Fruit implements Edible { // Data fields, constructors, and methods...

  • What is wrong with this Code? Fix the code errors to run correctly without error. There...

    What is wrong with this Code? Fix the code errors to run correctly without error. There are seven parts for one code, all are small code segments for one question. All the 'pets' need to 'speak', every sheet of code is connected. Four do need need any Debugging, three do have problems that need to be fixed. Does not need Debugging: public class Bird extends Pet { public Bird(String name) { super(name); } public void saySomething(){} } public class Cat...

  • What is output? public abstract class People { protected string name; protected int age; public abstract...

    What is output? public abstract class People { protected string name; protected int age; public abstract void PrintInfo(); public void PrintInformation() { System.out.println("In Base Class People"); public class Teacher extends People { private int experience; public void PrintInfo() { System.out.println("In Child Class Teacher"); public class Principal extends Teacher { public void PrintInformation() { System.out.println("In Child Class Principal"); public static void main(String args[]) { Principal tim; tim = new Principal(); tim.PrintInfo(); In Base Class People Error: Compiler error In Child Class...

  • ble and instance variable, and then use clas 4. Please discuss the difference between class variable...

    ble and instance variable, and then use clas 4. Please discuss the difference between class variable and instant variable to complete the following code for the count of number of stud public class Student _//q1: fill this line to create a class variable num. public Student 1/ 22: fill this line to increase num. public static int getNum() return num; public static void main(String[] args) { Student stl=new Student O; Student st2-new Student ; Student st3-new Student ; //q3: fill...

  • import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...

    import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {        Student s1 = new Student();         Student s2 = new Student("Smith", "123-45-6789", 3.2);         Student s3 = new Student("Jones", "987-65-4321", 3.7);         System.out.println("The name of student #1 is ");         System.out.println("The social security number of student #1 is " + s1.toString());         System.out.println("Student #2 is " + s2);         System.out.println("the name of student #3 is " + s3.getName());         System.out.println("The social security number...

  • The current code I have is the following: package uml; public class uml {        public...

    The current code I have is the following: package uml; public class uml {        public static void main(String[] args) {              // TODO Auto-generated method stub        } } class Account { private String accountID; public Account(String accountID) { this.accountID = accountID; } public String getAccountID() { return accountID; } public void setAccountID(String accountID) { this.accountID = accountID; } @Override public String toString() { return "Account [accountID=" + accountID + "]"; } } class SuppliesAccount extends Account { private...

  • Show the output of running the class Test in the following code lines: interface A {...

    Show the output of running the class Test in the following code lines: interface A { void print (); } class C ( class B extends C implements A { public void print() { } } class Test { public static void main(String[] args) { B b = new B(); if (b instanceof A) System.out.println("b is an instance of A"); w class Test { public static void main(String[] args) { B b = new B(); if (b instanceof A) System.out.println("b...

  • Create an abstract Student class for Parker University. The class contains fields for student ID number,...

    Create an abstract Student class for Parker University. The class contains fields for student ID number, last name, and annual tuition. Include a constructor that requires parameters for the ID number and name. Include get and set methods for each field; the setTuition() method is abstract. Create three Student subclasses named UndergraduateStudent, GraduateStudent, and StudentAtLarge, each with a unique setTuition() method. Tuition for an UndergraduateStudent is $4,000 per semester, tuition for a GraduateStudent is $6,000 per semester, and tuition for...

  • Java. What is the output of this code? Ace.java public class Ace { private double a;...

    Java. What is the output of this code? Ace.java public class Ace { private double a; public Ace ( double x) {       a = x; } public void multiply (double f) {       a *= x;         } public String toString () {       return String.format ("%.3f", x); AceDem.java public class AceDemo { public static void main(String args[]) {    Ace card = new Ace (2.133); card.multiply (.5); System.out.println (card); } }

  • Deliverables app.java, myJFrame.java, myJPanel.java and student.java as requested below. (Use the student.java class that you already...

    Deliverables app.java, myJFrame.java, myJPanel.java and student.java as requested below. (Use the student.java class that you already have from previous labs) Contents Based on the graphics you learned this week Create an instance (an object, i.e., st1) of student in myJPanel Display his/her basic information Display for 10 times what he/she is up to (using the method whatIsUp() that your student class already has) -------------------------------------------------------------------------------------------------- \\app.java public class app { public static void main(String args[]) { myJFrame mjf = new myJFrame();...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT