class Box { double width; double height; double depth; }

Slides:



Advertisements
Similar presentations
UNIT II DATA TYPES OPERATORS AND CONTROL STATEMENT 1.
Advertisements

The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
1 Calling within Static method /* We can call a non static method from a static method but by only through an object of that class. */ class Test1{ public.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
***** SWTJC STEM ***** Chapter 4-1 cg 42 Object Oriented Program Terms Up until now we have focused on application programs written in procedural oriented.
1 CLASSES. 2 Class Fundamentals It defines a new data type Once defined, this new type can be used to create objects of that type A class is a template.
1 Class Constructor Is a specific method Used to initialize the class’s fields Having the same name as the declaring classclass Doesn’t have return type(even.
INTRODUCTION TO JAVA.
Lecture 2 Classes and objects, Constructors, Arrays and vectors.
Huron High School AP Computer Science Instructor: Kevin Behemer S. Teacher: Guillermo Moreno.
Metode di Java Risanuri Hidayat, Ir., M.Sc.. Pendahuluan Classes usually consist of two things: instance variables and methods. The topic of methods is.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
04/07/041 Intro to JAVA By: Riyaz Malbari. 04/07/042 History of JAVA  Came into existence at Sun Microsystems, Inc. in  Was initially called “
Methods CSC 171 FALL 2004 LECTURE 3. Methods Variables describe static aspects – “nouns” Methods describe dynamic aspects – “verbs”, “behaviors” – Methods.
UML Basics & Access Modifier
Class and Object. Class vs Object Let us consider the following scenario… Class defines a set of attributes/fields and a set of methods/services. Object.
class Box { Box is new data type of the class. double width;
Java Classes Methods Objects. Classes Classes We have been using classes ever since we started programming in Java Whenever we use the keyword class.
Inheritance. Introduction Inheritance is one of the cornerstones of object-oriented programming because it allows the creation of hierarchical classifications.
A Closer Look at Methods and Classes. Overloading Methods In Java it is possible to define two or more methods within the same class that share the same.
1. 2 Reference... Student stu; Reference of Student stu When the reference is created it points to a null value. Before access the reference, objects.
Interfaces. –An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java.
ICS 201 Introduction to Computer Science
Overloading There is another aspect to polymorphism: Overloading Overloading is not overriding. In Turkish: Overridding: eskisini (geçersiz kılmak) Overloading:
Structured Programming Good for programming in the small Often doesn't scale up Limitations –Changes at top may affect lower-level algorithms –Code reuse.
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
Classes One class usually represents one type of object –May contain its own member variables –May contain its own methods to operate on the member variables.
Objects and Classes Mostafa Abdallah
What is an Object? Real world objects are things that have: 1) state 2) behavior Example: your dog: 1) state – name, color, breed, sits?, barks?, wages.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Presented By Venkateswarlu. B Assoc Prof of IT Dept Newton’s Institute of Engineering.
Object- Oriented Programming (CS243) Dr Walid M. Aly lec4 1 Dr Walid M. Aly 1 Lecture 4 Object- Oriented Programming (CS243) Group home page:
1 CLASSES. 2 Class Fundamentals It defines a new data type Once defined, this new type can be used to create objects of that type A class is a template.
Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design.
Topics Instance variables, set and get methods Encapsulation
JAVA METHODS (FUNCTIONS). Why are they called methods? Java is a strictly object-oriented programming language Methods are functions inside of objects.
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Staples are our staple Building upon our solution.
OOP Features Object Oriented Programming Main issues in software engineering – –maintainability, reusability, portability, security, integrity, user.
I – UNIT Procedure Oriented Programming
I – UNIT Procedure Oriented Programming
Introducing Classes By: Pavan D.M.
Inheritance class TwoDShape { private double width;
AKA the birth, life, and death of variables.
Department of Computer Science
INHERITANCE.
I – UNIT Procedure Oriented Programming
OBJECT ORIENTED PROGRAMMING
II – UNIT Procedure Oriented Programming
I – UNIT Procedure Oriented Programming
Constructor Overloading
Introducing Classes By: Pavan D.M.
Introduction to Classes
I – UNIT Procedure Oriented Programming
OBJECT ORIENTED PROGRAMMING
INHERITANCE.
Unit-2 Objects and Classes
Assignment 7 User Defined Classes Part 2
Classes Lecture 7 from Chapter /1/11.
JAVA Constructors.
■ Simple ■ Secure ■ Portable ■ Object-oriented ■ Robust
class PrintOnetoTen { public static void main(String args[]) {
JAVA 22 February 2019 DEPARTMENT OF CSE.
Scope of variables class scopeofvars {
Index Understanding static Final Inheritance Super
Classes One class usually represents one type of object
OOP With Java/ course1 Sundus Abid-Almuttalib
Local variables and how to recognize them
Presentation transcript:

class Box { double width; double height; double depth; } // This class declares an object of type Box. class BoxDemo { public static void main(String args[]) { Box mybox = new Box(); double vol; // assign values to mybox's instance variables mybox.width = 10; mybox.height = 20; mybox.depth = 15; // compute volume of box vol = mybox.width * mybox.height * mybox.depth; System.out.println("Volume is " + vol); }}

class Box { double width; double height; double depth;} class BoxDemo2 { public static void main(String args[]) { Box mybox1 = new Box(); Box mybox2 = new Box(); double vol; mybox1.width = 10; mybox1.height = 20; mybox1.depth = 15; mybox2.width = 3; mybox2.height = 6; mybox2.depth = 9; vol = mybox1.width * mybox1.height * mybox1.depth; System.out.println("Volume is " + vol); vol = mybox2.width * mybox2.height * mybox2.depth; }}

// display volume of a box void volume() { class Box { double width; double height; double depth; // display volume of a box void volume() { System.out.print("Volume is "); System.out.println(width * height * depth); }

public static void main(String args[]) { Box mybox1 = new Box(); class BoxDemo3 { public static void main(String args[]) { Box mybox1 = new Box(); Box mybox2 = new Box(); // assign values to mybox1's instance variables mybox1.width = 10; mybox1.height = 20; mybox1.depth = 15; /* assign different values to mybox2‘s instance variables */ mybox2.width = 3; mybox2.height = 6; mybox2.depth = 9; // display volume of first box mybox1.volume(); // display volume of second box mybox2.volume(); }}

// This is the constructor for Box. Box() { class Box { double width; double height; double depth; // This is the constructor for Box. Box() { System.out.println("Constructing Box"); width = 10; height = 10; depth = 10; } // compute and return volume double volume() { return width * height * depth;

Parameterized Constructors class Box { double width; double height; double depth; // This is the constructor for Box. Box(double w, double h, double d) { width = w; height = h; depth = d; } // compute and return volume double volume() { return width * height * depth;