CS 2336 Quiz 3

¡Supera tus tareas y exámenes ahora con Quizwiz!

___ is a construct that defines objects of the same type

A class

Which of the following is incorrect?

A. A constructor may be static.

What is true regarding abstract method?

A. Abstract classes have constructors B. A class that contains abstract methods must be abstract C. It is possible to declare an abstract class that contains no abstract methods D.An abstract method cannot be contained in a nonabstract class

Analyze code 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; Public String toString(){ Return "A's x is " + x; } }

A. When executing System.out.println(a2), the toString method in the Object class is invoked B. When executing System.out.println(a1), the toString method in the class A is invoked

Which of the following class definitions defines a legal abstract class?

Abstract class A {abstract void unfinished(); }

_____ represents an entity in the real world that can be distinctly identified

An object

Which of the following are incorrect?

A constructor may be static

Which of the following is INCORRECT?

A) An interface may contain constructors B) The constructors in an abstract class are private C) You may declare a final abstract class

person Student

What is the output of the following code? Public class Test{ Public static void main(String[] args){ New Person().printPerson(); New Student().printPerson(); } } Class Student extends Person{ Public String getInfo(){ Return "Student"; } } Class Person{ Public String getInfo(){ Return "Person"; } Public void printPerson(); System.out.println(getInfo()); } }

Which statements regarding the super keyword is incorrect?

You can use super.super.p to invoke a method in supercass's parent class.

What is the output of the following code? Public class Test{ Public static void main(String[] args){ New Person().printPerson(); New Student().printPerson(); } } Class Student extends Person{ Public String getInfo(){ Return "Student"; } } Class Person{ Public String getInfo(){ Return "Person"; } Public void printPerson(){ System.out.println(getInfo()); } }

person Student

What is the output of the following code? Public class Test1{ Public static void main(String [] args){ ChildClass c = new ChildClass(); c.print(); } } Class ParentClass { Int if = 3; Void print() { System.out.println(id); } } Class ChildClass extends ParentClass { Int id = 4; }

3

__ is a reference type.

A) A class type B) Interface type C) Array type

Which of the following statements are true?

A) A subclass usually extended to contain more functions and more detailed information than its superclass B) Class A extends B means A is a subclass of B

Which of the following are true?

A) To override a method, the method must be defined in the subclass using the same signature and compatible return type as in its superclass B) Overloading a method is to provide more than one method with the same name but with different signatures to distinguish them C) A private method cannot be overridden. If a method defined in a subclass is private in its superclass, the two methods are completely unrelated. D) It is a compilation error if two methods differ only in return type in the same class E) A static method cannot be overridden. If a static method defined in the superclass is redefined in a subclass, the method defined in the superclass is hidden.

Which of the following statements are true?

A) You can always pass an instance of a subclass to a parameter of its superclass type. This feature is known as polymorphism . B) Dynamic binding can apply to instance methods. A method may be implemented in several subclasses, C) The Java virtual machine dynamically binds the implementation of the method at runtime D) The compiler finds a matching method according to parameter type, number of parameters, and order of the parameters at compilation time

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

A) m(new Object()) causes an error B) M(new Person()) causes an error

Suppose A is an interface, B is a concrete class with a default constructor that implements A. Which of the following is correct?

A. B b = new B(); B. A a = new B();

Show the output of running the class Test Interface A{ } Class C{ } Class B extends D implements A{ } Public 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"); If (b instanceof C) System.out.println("b is an instance of C"); } } Class D extends C{ }

B is an instance of A followed by b is an instance of C

hat is the output of the running class Test? Public class Test{ Public static void main(String [] args){ New Circle(); } } Public abstract class GeometricObject{ Protected GeometricObject(){ System.out.print("A"); } Protected GeometricObject(String color, boolean filled) { System.out.print("B"); } } Public class Circle extends GeometricObject { // Default constructor Public Circle(){ This (1.0); System.out.print("C"); } Public Circle( double radius){ This (radius, "white", false); System.out.print("D") } Public Circle (Double radius, String color, boolean filled){ super(color, filled); System.out.print("E"); } }

BEDC

Object oriented programming allow you to derive new classes from existing classes. This is called__________.

Inheritance

Object oriented programming allows you to derive new classes from existing classes. This is called _____.

Inheritance

The relationship between interface and the class that implements it is

Inheritance

What is the best relationship between Employee and Faculty?

Inheritance

Which of the following is a correct interface?

Interface A {void print();}

Which of the following declares an abstract method is an abstract java class?

Public abstract void method();

Analyse the following code: Public class Test{ Public static void main(String[]args){ New B(); } } Class A{ Int i = 7; Public A(){ System.out.println("i from A is " + i); } Public void set(int i){ This.i = 2 * i; } } Class B extends A{ Public B(){ set(20); // System.out.println("i from B is " + i); } Public void set(int i){ This.i = 3 * i; } }

The constructor of class A is called and it displays "i from A is 7".


Conjuntos de estudio relacionados

Answer the following questions...

View Set

Biochemistry unit test section 1

View Set

Chapter 58: Drugs for Thyroid Disorders

View Set

"Psychiatric/Mental Health Nursing - Psychobiological Disorders + Foundations"

View Set

What is a Mutual Fund?/Whats is risk? 1

View Set

Patho/Pharm 4 Week 1, 2, 5 Combined (Does not include week 3-Mental Health)

View Set

Seizure Pediatric Practice Questions (Test #2, Fall 2020)

View Set

Science - Lunar Cycle from crossword

View Set