Java_ classes and objects 13_ small exercises

Source: Internet
Author: User
Tags modifier modifiers

One

1: What is the difference between a local variable and a member variable?

A: Different positions in the class

B: Different locations in memory

C: Different life cycle

D: Different initialization values

2: The formal parameter is the basic type and the reference type question respectively?

Formal parameters: The change of the basic type parameter does not affect the actual parameters

Formal parameters: Change of reference type parameter directly affects actual parameters

If the formal parameter of a method is the name of a class, then the object of that class is required here.

3: What is an anonymous object? What is the application scenario?

An object without a name.

Application Scenarios:

A: Call the method, just call it once

B: Pass as actual parameter

4: What is encapsulation? What is the embodiment of encapsulation in Java? Please give an example.

Encapsulation: Hides the implementation details and provides a common way to access.

The embodiment of the package:

Class, method, private modifier member variable

What is the 5:this keyword? What is the application scenario for this keyword?

This: The object that represents the current class is applied

Scenario: Solving the problem of local variable hidden member variables

6: What is the function of the construction method? What are the characteristics of the construction method?

What are the considerations for constructing a method? Can I write a return statement in the construction method?

Function: Used to initialize the data of an object

Characteristics:

A: The method name is the same as the class name

B: There is no return value type, and even void cannot have

C: no return value

Precautions:

A: If we do not give the construction method, the system provides a default parameterless construction method

B: If we give a construction method, the system will no longer provide a default construction method

This time we want to use, we must provide ourselves. It is recommended that you provide a method of non-parametric construction.

Class Student {

private String name;

Public Student () {}

Getxxx/setxxx

}

The constructor method can have a return statement, but cannot have a definite return value. That is to say return;

7: How many ways are there to assign a value to a member variable?

A:setxxx ()

B: With parameter construction method

8: Standard code writing and testing:

A: Cases of Student class

B: Case of mobile phone class

C: Case of the rectangular class

Class Student {

private String name;

private int age;

Public Student () {}

Public String GetName () {

return name;

}

public void SetName (String name) {

THIS.name = name;

}

public int getage () {

return age;

}

public void Setage (int.) {

This.age = age;

}

}

Class Studentdemo {

public static void Main (string[] args) {

Student s = new Student ();

S.setname ("Brigitte");

S.setage (27);

System.out.println (S.getname () + "---" +s.getage ());

}

}

9: Member variable initialization procedure for a class

Student s = new Student ();

A: Load the Student.class file into memory (class loader)

B: Open space in stack memory for s

C: Application space for student objects in heap memory

D: Default initialization of member variables for student objects

E: Display class for the member variable of the student object.

F: Initialize the member variables of the student object by constructing the method

G: Assign the address of the heap memory to the s variable

What are the 10:static keywords? What are the characteristics? When to use it?

Static statically means that member variables and member methods can be modified.

Characteristics:

A: Loaded with the load of the class

B: Priority and object presence

C: Shared by all objects

D: Can be called by the class name

When do you use it?

A: When a member is shared by all objects.

B: When the tool class.

11: The difference between a static variable and a member variable

A: Belong to different

B: Different memory locations

C: Different life cycle

D: Call Different

12:main how to interpret various modifiers and parameters?

Public: Permission modifier, maximum permissions

Static: You can not create an object

void: return value to JVM meaningless

Main: A method name, everyone is the default

String[] args: receiving keyboard input objects

Two

1: What is a code block? What are the categories and characteristics of code blocks?

2: Static code block, construct code block, construct method execution flow?

3: Inheritance Overview

4: Benefits of inheritance

Characteristics of inheritance in 5:java

What are the considerations of inheritance in 6:java? And when do we use inheritance?

7: Member access features in inheritance

A: Member variables

Accessing a variable in a subclass method

B: Member Method

Accessing a method from a subclass object in a test class

8: The execution flow of the constructor method in the inheritance? If the parent does not have a parameterless constructor method, what should the subclass do?

9: Interview Questions:

What is the difference between a method override and a method overload? Can the method overload change the return value type?

Overload

Override

What do the This keyword and super keywords stand for? And their respective usage scenarios and roles.

10: Inheritance Case Exercise

11: Guess the number of small game exercises.

Learn from the API and use the random () method of the Math class.

Three

What can I do with 1:final keywords? What are the characteristics?

The final meaning. You can modify classes, methods, and variables.

It modifies the class, and the class cannot be inherited

It modifies the method, and the method cannot be overridden

It modifies variables, variables are constants

2:final the key word of the question?

A: Modifying local variables

Base type: value cannot be changed

Reference type: Address value cannot be changed

B: Timing of initialization

At the time of definition

In the construction method

3: What is polymorphism, and what is the premise?

The different states that the same object shows at different times

A: Having a succession or realization relationship

B: A method of rewriting

C: There are parent or parent interface references to child class objects

4: What are the characteristics of member access in polymorphism?

Member variables

Compile look left, run look left

Member Methods

Compile look left, run look right

Static methods

Compile look left, run look left

5: The benefits and drawbacks of polymorphism? How to solve the drawbacks of polymorphism?

Benefits:

Maintainability and extensibility

Cons: Parent classes cannot use subclass-specific features

How to solve it?

A: Create A Subclass object. (One more object in memory)

B: Down transformation

6: What is the upward transformation? What is the downward transition?

Child-Parent

Parent-Child

7: Multi-state exercise

Do It Yourself

8: Abstract class overview and its characteristics?

Abstract class: When inheriting, several methods are extracted, and some methods are not identical implementations of each subclass.

At this point, you should not provide a concrete implementation of such a method, but the method of not providing a concrete implementation is an abstract method.

In a class, if there is an abstract method, the class must be defined as an abstract class.

Characteristics:

A: Abstract class or abstract method modified by abstract

B: Abstract classes do not necessarily have abstract methods, but classes with abstract methods must be abstract classes

C: Abstract class cannot be instantiated

D: Subclass of Abstract class

A: Is abstract class

B: It's a concrete class, so rewrite all the abstract methods

9: Abstract class member characteristics?

A: Member variables

There are variables, there are constants

B: Construction method

Yes. Initialization for subclass access to the parent class data

C: Member Method

There are abstract methods, there are non-abstract methods

10: Abstract class practice?

11: Small problem of abstract class

A: If there is no abstract method for a class, can it be defined as an abstract class? If so, what's the point?

B:abstract cannot coexist with which keywords

Final

Static

Private

12: Overview of the interface and its features?

Interface: When an inheritance system needs to extend functionality, it should implement the interface.

Characteristics:

A: interface modified with interface

B: Class implementation interface with implements modification

C: interface cannot be instantiated

D: implementation of the interface

A: abstract class

B: Concrete class, overriding all abstract methods in an interface

13: Features of the interface members?

A: member Variable static constants

B: The member method is abstract

14: What is the difference between an abstract class and an interface?

A: Member Differences

B: Relationship Difference

C: Differences in design concepts

"is a"

"Like a"

15: The practice of the interface?

16: Case

Cat and dog cases, add extra features to the high jump

Teacher and student cases, adding extra features for smoking

Coach and athlete case (student analysis then explain)

Four

1: Formal parameters and return value issues

Formal parameters

Basic type

Reference type

return value type

Basic type

Reference type

2: Package Definition and precautions

Package

First valid statement

Only

3: Guide Package and Precautions

Import

Java.lang do not need to import

Java.xxx.yyy. class name; Level of import to class

java.xxx.yyy.*; This is also possible, but not recommended

4: Four permission modifiers and their characteristics

  

5: Common modifiers and combinations

Class: Public

Member Variable: private

Construction Method: Public

Member Method: Public

6: Overview of internal classes and access features

Define a class inside another class, called an inner class.

Access features:

Inner classes can access members of external classes directly, including private

External classes accessing members of inner classes need to create objects

7: Classification of inner classes

Varies by location

member Inner class

Local inner class

8: Anonymous inner class format and application and face questions

New class name or interface name () {

Override method;

}

9: Take a look at the object-oriented part of the summary. Ready to use later.

You have a question, write it down and ask me

Java_ classes and objects 13_ small exercises

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.