Conditional Statements

Slides:



Advertisements
Similar presentations
Java Language Quick-Reference Guide B. Oracle10g: Java Programming B - 2 Console Output Java applications and applets can output simple messages to the.
Advertisements

Object Oriented Programming with Java
OOP Abstraction Classes Class Members: Properties & Methods Instance (object) Encapsulation Interfaces Inheritance Composition Polymorphism Using Inheritance.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 12 th -13 th Lecture Pavel Ježek.
Written by: Dr. JJ Shepherd
Final and Static Keywords. Creating constants  There will be occasions where data items in a program have values that do not change.  Maximum score.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
A Java Syntax Primer Yong Choi School of Business CSU, Bakersfield.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Inline Function. 2 Expanded in a line when it is invoked Ie compiler replace the function call with function code To make a function inline the function.
Java versus C# An introduction to C# and Visual Studio.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Multiple Choice Solutions True/False a c b e d   T F.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
Introduction to Java Prepared by: Ahmed Hefny. Outline Classes Access Levels Member Initialization Inheritance and Polymorphism Interfaces Inner Classes.
Class Inheritance UNC-CHAPEL HILL COMP 401 BRIAN CRISTANTE 5 FEBRUARY 2015.
The Java Programming Language
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
ILM Proprietary and Confidential -
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
1 Interfaces and Abstract Classes Chapter Objectives You will be able to: Write Interface definitions and class definitions that implement them.
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
CIS 3301 C# Lesson 3 Control Statements - Selection.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Access Modifiers Control which classes use a feature Only class-level variables may be controlled by access modifiers Modifiers 1. public 2. protected.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
Introduction to C# By: Abir Ghattas Michel Barakat.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Control Flow Statements
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
Presentation By :- Nikhil R. Anande ( ) Electronic & Communication Engineering. 3 nd Year / 5 th Semester FACULTY GUIDE : RAHIUL PATEL SIR MICROCONTROLLER.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Lecture 5:Interfaces and Abstract Classes
Information and Computer Sciences University of Hawaii, Manoa
C# for C++ Programmers 1.
Chapter 4 Assignment Statement
CIS 200 Test 01 Review.
2.7 Inheritance Types of inheritance
Loops in Java.
Inheritance and Polymorphism
Methods Attributes Method Modifiers ‘static’
University of Central Florida COP 3330 Object Oriented Programming
Chapter 3 Assignment Statement
Packages, Interfaces & Exception Handling
Nested class.
Interfaces.
C# In many ways, C# looks similar to Java
OOP’S Concepts in C#.Net
null, true, and false are also reserved.
Interface.
Introduction to Java Programming
Interfaces.
Advanced Java Programming
Focus of the Course Object-Oriented Software Development
Chapter 14 Abstract Classes and Interfaces
Chap 2. Identifiers, Keywords, and Types
Controlling Program Flow
Corresponds with Chapter 5
Presentation transcript:

Conditional Statements No arithmetic expressions are allowed where boolean expressions are expected Thus, if you write: if ( x = y ) // compilation error

Operator Evaluation Order x = a++ + --a; left to right x = 10 right to left x = 8 X=?

Loops C# provides a number of the common loop statements while do-while for foreach

‘foreach’ Loop Syntax foreach (variable1 in variable2) statement[s] The 'foreach' loop is used to iterate through the values contained by any object which implements the IEnumerable interface When a 'foreach' loop runs, the given variable1 is set in turn to each value exposed by the object named by variable2 int[] a = new int[]{1,2,3}; foreach (int b in a)     System.Console.WriteLine(b);

Switch switch (expression) { case constant-expression: statements Expression – an integral or string expression switch (expression) { case constant-expression: statements jump statement [default: ] } Jump statement is required for each block – even in default block Fall through is allowed to stack case labels Control does not fall through

switch(a) {      case 2:          Console.WriteLine("a>1 and ");          goto case 1;      case 1:       Console.WriteLine("a>0");          break;      default:          Console.WriteLine("a is not set");          break; }

void func(string option) { switch (option) case "label": goto case "jump": case "quit": return; case "spin": for(;;){ } case "jump": case "unwind": throw new Exception(); default: break; }

Class Class Attributes Attributes are used to give extra information to the .NET compiler E.g. it’s possible to tell the compiler that a class is compliant with the .NET Common Language Specification [CLSCompliant(true)] public class myClass { //class code7 }

Class Class attributes Class modifiers ‘public’ ‘private’ ‘protected’ ‘internal’ Accessible only to types within the same assembly Similar to a package (in Java) ‘internal protected’ ‘new’

new The 'new' keyword can be used for 'nested' classes A nested class is one that is defined in the body of another class; it is in most ways identical to a class defined in the normal way, but its access level cannot be more liberal than that of the class in which it is defined A nested class should be declared using the 'new' keyword just in case it has the same name as (and thus overrides) an inherited type

‘abstract’ A class declared as 'abstract' cannot itself be instantiated - it is designed only to be a base class for inheritance ‘sealed’ A class declared as 'sealed' cannot be inherited from structs vs. sealed classes