Basics of Object-Oriented Programming

Published on June 2017 | Categories: Documents | Downloads: 32 | Comments: 0 | Views: 195
of 3
Download PDF   Embed   Report

Comments

Content

Basics of Object-Oriented Programming in JAVA
1) What is a class? A class can be defined as a template that describes the behaviours / states that object of its type support. 1.1) What is a local variable? Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed. 1.2) What is an instance variable? Instance variable is a variable within a class but outside any method. These variables come into play when the class is loaded. Instance variable can be accessed from inside any method, constructor or blocks of that particular class. What is a class variable? Class variables are variables declared within a class outside any method with the static keyword.

1.3)

2) What are objects? That has a state and exhibits specific behaviour. For example a dog, the state of the dog can be colour, name, breed and the behaviours exhibited by them are wagging, barking, eating. 3) What are the advantages of using JAVA? The advantages of using JAVA are 3.1) Object Oriented: In JAVA everything is an object. JAVA can be easily extended since it is based on the Object Model. 3.2) Platform Independent: Unlike many other programming languages including C and C++ when JAVA is compiled it is not compiled into platform specific machine rather into platform independent byte code. The byte code is interpreted by virtual machine on whichever platform it is being run. Architecture neutral: JAVA compiler generates an architecture neutral object file format which makes the compiled code to be executable on many processors with the present JAVA run time environment. Portable: Being architecture neutral and having no implementation dependent aspects of the specification makes JAVA portable. Robust: JAVA makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and run time checking. High-performance: with the Just-In Time compilers JAVA enables high performance. Dynamic: JAVA programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run time.

3.3)

3.4)

3.5)

3.6)

3.7)

4) What is Just-In Time Compilation? In computing Just-In Time Compilation also known as Dynamic Translation is a method to improve the run time performance of the computer programs based on byte code (virtual machine code). Since byte code is interpreted it executes slower than compiled machine code unless it is actually compiled to machine code which could be performed before the execution, making the program loading slow or during the execution. In case of Just-In Time Compilation the program is stored in memory as byte code, but the code segment currently running is preparatively compiled to physical machine code in order to run faster. 5) What do you mean by the term ‘Encapsulation’ in JAVA? Encapsulation in JAVA is the technique of making the fields in a class private and providing the access to the fields via public methods. If a field is declared private it cannot be accessed by anyone outside the class thereby hiding the fields within the class. For this reason encapsulation is also referred to as Data Hiding. 6) What do you mean by the term ‘Inheritance’ in JAVA? Inheritance can be defined as the process where one object acquires the properties of another. With the use of inheritance the information is made manageable in a hierarchical order. 7) What do you mean by the term ‘Overriding’? If a class inherits a method from its super-class then there is a chance to override the method provided that it is not marked final. The benefit of overriding is ability to define a behaviour that is specific to the sub class type which means a subclass can implement a parent class method based on its requirement. 8) What do you mean by the term ‘Polymorphism’? Polymorphism is the ability of an object to take many forms. The most common use of polymorphism in object oriented programming occurs when a parent class reference is used to refer to a child class object. A reference variable can refer to any object of its declared type or any subtype of its declared type. A reference variable can be declared as a class or interface type. 9) What is a JAVA method? A JAVA method is a collection of statements that are grouped together to perform an operation. The parts of the method body are 9.1) Modifiers: The modifier tells the compiler how to call the method. This defines the access type of the method. 9.2) Return Type: A method may return value. The returnValueType is the data type of the value the method returns. Some methods perform the desired operations without returning a value. In this case the returnValueType is the keyword void. Method Name: The actual name of the method. Parameters: When a method is invoked we pass a value to the parameter. This parameter is referred to as the actual parameter or argument. The parameter list refers to the type, order and number

9.3) 9.4)

9.5)

Method Body: The method body contains a collection of statements that defines what the method does.

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close