Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Java Notes

The document discusses object-oriented programming concepts like classes, objects, attributes, methods, constructors, inheritance, polymorphism, encapsulation, and abstraction. It provides examples and explanations of key concepts.

Uploaded by

amrt6958
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Java Notes

The document discusses object-oriented programming concepts like classes, objects, attributes, methods, constructors, inheritance, polymorphism, encapsulation, and abstraction. It provides examples and explanations of key concepts.

Uploaded by

amrt6958
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Notes:

1- Scanner method nextLine


Reads characters typed by the user until the newline
character is encountered.
Scanner method next
Reads individual words

2-Classes System and String are in package


java.lang.

Classes that are compiled in the same directory on disk


are in the same package—known
as the default package.

3-Attributes are represented as variables in a


class declaration.
Called fields.
Instance variable
When each object of a class maintains its own
copy of an attribute, the field is
an instance variable
4-Declaring instance private
is known as data hiding or information hiding.

5-it is elements are assigned the default value


for the numeric primitive data types 0,
'\u0000' for char types, and
false for boolean types.
0 int
0.0 double
null string, array, object class

6-Classes often provide public methods to


allow clients to set (i.e., assign
values to) or get (i.e., obtain the values of)
private instance variables

7-The primitive types are boolean , byte


, char , short , int , long ,
float and double .
•All nonprimitive types are reference types.
8 A constructor must have the same
-

name as the class.

9-By default, the compiler provides a default


constructor with no parameters in
any class that does not explicitly include a
constructor.

10-Sometimes there may be two or more possible matches for an invocation of a


method, but the compiler cannot determine the most specific match. This is
referred to as ambiguous invocation. Ambiguous invocation is a compilation
error.

11-A constant is declared with the keyword const—its value cannot be


changed after the constant is declared.
12-The Math class contains the following trigonometric methods and each
method has a single double parameter, and its return type is double.

13- The output from invoking Math.random() is random double value in


the range [0.0, 1.0).
14-a + Math.random() * b :
Returns a random number between
a and a + b, excluding a + b.

15-Array is a data structure that represents a collection of the same types of data
and the value of the variable is null, size is fixed.
16-The state of an object (also known as its properties or attributes) is
represented by data fields.

17-Constructors are a special kind of method

18-multiple constructors can have the


same name but different signatures.

19-A static variable is shared by all objects of the class.


20-Constants in a class are shared by all objects of the class. Thus, constants
should
be declared as final static. For example, the constant PIin the Mathclass .
21-Object-oriented programming allows you to define new classes from existing
classes. This is called inheritance.
22-The keyword super refers to the superclass of the class in which
super appears. It can be used in two ways:
■ To call a superclass constructor.

■ To call a superclass method.

23-A hidden instance variable can


be accessed by using the keyword this.
Use this to refer to the object that invokes the instance method.
 Use this to refer to an instance data field.
 Use this to invoke an overloaded constructor of the same class.

24-compiler automatically puts super() as the first


statement in the constructor.
25-To override a method, the method must be defined in the subclass using the
same signature and the same return type as in its superclass.

26-Overloading means to define multiple methods with the same name but
different signatures. Overriding means to provide a new implementation for a
method in the subclass

27-Private members can be accessed only from inside of the class, and public
members can be accessed from any other classes.

28-A final data field is a constant.

You might also like